We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge 4 - Colour buttons
#14
Hi,

Like others, I'm not really sure what the issue is and don't think describing how it works will add anything.

In my example I set the button to the element of an array.

Code:
button[i] = Controls.AddButton("",buttonX[i],buttonY[i])

In your example you use separate variables for each button:

Code:
ButtonRed = Controls.AddButton("",10,10)

In these cases, they "work independently of the internal button name ".

In the example by JR, he does use the internal variable name - it works, but I would always prefer to store in a local user variable.  This looks like maybe a lucky oversight by JR.

Code:
Button1=Controls.AddButton("My Button1",0,0)
...
If Controls.LastClickedButton = "Button1" then

The only time I might consider using the internal name is to access a large number of shapes without referring to user variables, for example removing Turtle lines (that are shapes). 

Equally, and proably better would be:

Code:
Button1=Controls.AddButton("My Button1",0,0)
...
If Controls.LastClickedButton = Button1 then

Actually, the following would also work, but clearly is harder to follow:

Code:
Controls.AddButton("My Button1",0,0)
...
If Controls.LastClickedButton = "Button1" then

This is partly why I used arrays to store the buttons in my example.

EDIT

Note the [i] array index in "button[i] = Controls.AddButton("",buttonX[i],buttonY[i]) ", which you missed in your post that confused me a bit.
Reply


Messages In This Thread
Challenge 4 - Colour buttons - by litdev - 09-04-2024, 06:06 PM
RE: Challenge 4 - Colour buttons - by jrmrhrb00 - 09-04-2024, 07:35 PM
RE: Challenge 4 - Colour buttons - by Scout - 09-04-2024, 09:23 PM
RE: Challenge 4 - Colour buttons - by litdev - 09-05-2024, 09:11 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-05-2024, 11:16 AM
RE: Challenge 4 - Colour buttons - by WhTurner - 09-07-2024, 12:01 PM
RE: Challenge 4 - Colour buttons - by Scout - 09-07-2024, 08:12 PM
RE: Challenge 4 - Colour buttons - by jrmrhrb00 - 09-08-2024, 11:02 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-08-2024, 08:45 PM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 02:28 AM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 04:07 AM
RE: Challenge 4 - Colour buttons - by litdev - 09-09-2024, 08:20 AM
RE: Challenge 4 - Colour buttons - by Scout - 09-09-2024, 09:26 AM
RE: Challenge 4 - Colour buttons - by z-s - 09-09-2024, 10:12 AM
RE: Challenge 4 - Colour buttons - by litdev - 09-09-2024, 11:16 AM

Forum Jump:


Users browsing this thread: 7 Guest(s)