I also used chatGPT for looking uo code and I repeated your question. But this time chatGPT gives a wrong answer!
—chatGPT: You will need to specify the group that the button should be added to by setting the group property of the button. The syntax for this is as follows: set the group of button [name of button] to [name of group] For example, if you wanted to create a button called "myButton" and add it to a group called "myGroup", you would use the following script: create button "myButton“ set the group of button "myButton" to "myGroup" create button "myButton“ set the group of button "myButton" to „myGroup" --- It is an error because group is not a property of a button! So, really be careful with copy&paste programming ;-) Cheers Torsten > Am 14.01.2023 um 22:14 schrieb Kaveh via use-livecode > <use-livecode@lists.runrev.com>: > > I just tried Google to the answer to a problem. Didn't get it first time, > so tried ChatGPT. I asked: > > *How do I add a button to a group in LiveCode using a script?* > > I got: > > *create button "myButton" in group "myGroup"* > > > *This command creates a new button object with the name "myButton" and > places it inside the group "myGroup".* > Just what I needed. > > You can also set properties of the button > > On Sat, 14 Jan 2023 at 20:09, Mark Smith via use-livecode < > use-livecode@lists.runrev.com> wrote: > >> Thanks for posting this Geoff. It’s the first time I've seen a ongoing >> dialog between a programmer and Chat GPT and the first thing I am struck by >> (but not the only thing) is it’s ability to deal with human ambiguity. For >> example, you ask it to modify the code to be an “on mouseUp handler in a >> button". But nowhere in its response is there any sign of a button. It just >> totally ignored that part of your request. The code it provides works in a >> card, a stack, a graphic image, an svg widget, in fact, in anything that >> accepts mouseUp input. And yet, it didn’t worry itself about that. Very >> interesting. It’s kind of like, “this works in a button, so good enough”. >> That is not the kind of “nuance” I am used to expecting from an AI. So, >> progress has clearly been made in interpreting what humans say (or ask) in >> a very loose way. >> >> The 2nd, and perhaps more astounding example, is when you ask it to >> "rewrite the code to be a function that takes an argument "n", repeats with >> 1 to n, and returns the results”. >> >> The really clever bit here is not that it rewrites the previous code into >> a function, but that it removes the bit about "put fizzbin into field >> “display””. How does it know that putting the result in a field is NOT the >> typical responsibility of a function? How does it know that that step needs >> to occur AFTER the function call? That is so high-level that I am sure lots >> of beginning programmers have made that mistake. It even comments on it in >> the documentation. So there is some very deep semantic understanding of >> programming code that is going on here. Because, you did not ask it to do >> that, but the fact that it did it anyway indicates it clearly understands >> what the purpose of a function is. >> >> Quite weird for me to comprehend how it knows that. Unless of course, you >> were somehow more specific than your examples illustrate. >> >> Mark >> >>> On 14 Jan 2023, at 3:22 am, Geoff Canyon via use-livecode < >> use-livecode@lists.runrev.com> wrote: >>> >>> So just now I put this in to chatgpt: >>> >>> "fizz bin" is a program that counts from 1 to 100, replacing every number >>> divisible by 5 with "fizz" and every number divisible by 7 with "bin"; >> and >>> numbers divisible by both 5 and 7 with "fizz bin". Write code in the >>> programming language livecode to execute "fizz bin" >>> >>> This is what ChatGPT responded with: >>> >>> repeat with x = 1 to 100 >>> if x mod 5 = 0 and x mod 7 = 0 then >>> put "fizz bin" >>> else if x mod 5 = 0 then >>> put "fizz" >>> else if x mod 7 = 0 then >>> put "bin" >>> else >>> put x >>> end if >>> end repeat >>> >>> That works as-is, but obviously the results fly by in the message box. >> So I >>> put a field and a button on a card, and edited to this, and it works >>> perfectly: >>> >>> on mouseUp >>> repeat with x = 1 to 100 >>> if x mod 5 = 0 and x mod 7 = 0 then >>> put "fizz bin" & cr after fld 1 >>> else if x mod 5 = 0 then >>> put "fizz" & cr after fld 1 >>> else if x mod 7 = 0 then >>> put "bin" & cr after fld 1 >>> else >>> put x & cr after fld 1 >>> end if >>> end repeat >>> end mouseUp >>> >>> Then as I was typing this email I realized I was potentially selling >>> chatgpt short, so I put this in: >>> >>> Modify that code so it works as an "on mouseUp" handler in a button, and >>> concatenates the results on individual lines, and puts the final result >>> into the field "display" >>> >>> And it output this: >>> >>> >>> on mouseUp >>> put "" into fizzbin >>> repeat with x = 1 to 100 >>> if x mod 5 = 0 and x mod 7 = 0 then >>> put "fizz bin" & return after fizzbin >>> else if x mod 5 = 0 then >>> put "fizz" & return after fizzbin >>> else if x mod 7 = 0 then >>> put "bin" & return after fizzbin >>> else >>> put x & return after fizzbin >>> end if >>> end repeat >>> put fizzbin into field "display" >>> end mouseUp >>> >>> And it followed that with instructions: >>> >>> This code uses the "on mouseUp" handler to execute the script when the >>> button is clicked. The results are concatenated and separated by a new >> line >>> using the "& return" operator after each output. The final result is >> placed >>> into a field with the name "display" using the "put" command. >>> >>> I'll save you the trouble: that code executes perfectly right out of the >>> box, with no errors, and of course even though I didn't ask it to, it >> uses >>> a variable to store the intermediate values, saving the field update for >>> the end. >>> >>> If I were writing it, I'd probably do something like >>> >>> on mouseUp >>> put "" into fizzbin >>> repeat with x = 1 to 100 >>> if x mod 5 = 0 then put "fizz " after fizzbin >>> if x mod 7 = 0 then put "bin " after fizzbin >>> if char -1 of fizzbin is space >>> then put return into char -1 of fizzbin >>> else put x & return after fizzbin >>> end repeat >>> put fizzbin into field "display" >>> end mouseUp >>> >>> That might be a bit faster, but probably not as clear. >>> >>> Finally, I gave it the input: >>> >>> Now rewrite the code to be a function named "fizzbin" that takes an >>> argument "n", repeats with 1 to n, and returns the results. >>> >>> function fizzbin n >>> put "" into fizzbin >>> repeat with x = 1 to n >>> if x mod 5 = 0 and x mod 7 = 0 then >>> put "fizz bin" & return after fizzbin >>> else if x mod 5 = 0 then >>> put "fizz" & return after fizzbin >>> else if x mod 7 = 0 then >>> put "bin" & return after fizzbin >>> else >>> put x & return after fizzbin >>> end if >>> end repeat >>> return fizzbin >>> end fizzbin >>> >>> This works perfectly, and chat gpt also documents its answer: >>> >>> This code defines a function named "fizzbin" which takes an argument "n" >>> that determines the range of the repeat loop. The function builds the >>> result string in a variable "fizzbin" and return the final result. The >>> calling script can then use the returned value for further processing or >>> for displaying in a field. >>> >>> Grammatical issue notwithstanding, that's good documentation. >>> _______________________________________________ >>> use-livecode mailing list >>> use-livecode@lists.runrev.com >>> Please visit this url to subscribe, unsubscribe and manage your >> subscription preferences: >>> http://lists.runrev.com/mailman/listinfo/use-livecode >> >> _______________________________________________ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your >> subscription preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode >> > > > -- > Kaveh Bazargan PhD > Director > River Valley Technologies <http://rivervalley.io> ● Twitter > <https://twitter.com/rivervalley1000> ● LinkedIn > <https://www.linkedin.com/in/bazargankaveh/> ● ORCID > <https://orcid.org/0000-0002-1414-9098> ● @kaveh1000@mastodon.social > <https://mastodon.social/@kaveh1000> > *Accelerating the Communication of Research* > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode