Code: Select all
set buttons custom
draw color 0,0,0
FOR x = 1 TO 10
FOR y = 1 TO 10
BUTTON btn TEXT str$(x+(y-1)*10) AT x*65,y*65 SIZE 60,60
btn = btn+1
NEXT y
NEXT x
Code: Select all
set buttons custom
draw color 0,0,0
FOR x = 1 TO 10
FOR y = 1 TO 10
BUTTON btn TEXT str$(x+(y-1)*10) AT x*65,y*65 SIZE 60,60
btn = btn+1
NEXT y
NEXT x
Code: Select all
''
Drawbuttons by rbytes
October 2017
''
' hide the control menu - screenwidth increases by 48 points
#.scrview(#.normal)
' get screen size and calculate scaling for device
x,y = #.scrsize()
rw = x/1280 ; rh = y/813
s = 1
u = 0
' create button matrix
' define template button and set common parameters
q=#.button
q.width = 50
q.height = 50
' create 100 buttons in a 10 x 10 matrix
> t, 1..100
' name temp as the number t
temp = #.str(t)
#.output(temp)
' create button from temp using button template
temp = q
' position the button
temp.x = 150 + s*60
temp.y = 120 + u*60
#.show(temp)
' draw rectangles where the buttons should be
#.drawrect(temp.x,temp.y,temp.x+50,temp.y+50)
s += 1
? s > 10
s = 1
u += 1
.
<
Code: Select all
> i, 1..5
a[i] = #.button
b = ~a[i]
b.y = i*40
b.text = "Button "+i
#.show(b)
<
>
> i, 1..#.size(a,1)
b = ~a[i]
? #.act(b), #.output(a[i].text)
<
<
In SPL it is Ok to redefine an object during runtime, so using "temp" as a text object and later as a button object is fine.rbytes wrote: ↑Sun Oct 15, 2017 6:11 pmHere is some code I created to try to name and display buttons dynamically. It doesn't work correctly, so I have modified the code to draw button-shaped rectangles where I hoped to generate buttons. The button 'temp' only appears once, as button 100. It does not take its name from the value of the variable temp, but from the letters 'temp'. So all my code does is create the same button 100 times!
temp can be repeatedly defined alternately as a variable and an object (button), as can be seen when I output its value. If I move the output statement to immediately after the line that creates the button, 'temp = q', the program ends with the error Wrong Object Type. I would expect that, but I would also expect the same error on the next loop iteration when I define the button object name 'temp' again as a numeric variable.
Code: Select all
''
Drawbuttons by rbytes
October 2017
''
' hide the control menu - screenwidth increases by 48 points
#.scrview(#.normal)
' get screen size and calculate scaling for device
x,y = #.scrsize()
rw = x/1280 ; rh = y/813
s = 1
u = 0
' create button matrix
' define template button and set common parameters
q=#.button
q.width = 50
q.height = 50
' create 100 buttons in a 10 x 10 matrix
> t, 1..100
' name temp as the number t
temp = #.str(t)
#.output(temp)
' create button from temp using button template
b[t] = q
' position the button
~b[t].x = 150 + s*60
~b[t].y = 120 + u*60
#.show(~b[t])
' draw rectangles where the buttons should be
#.drawrect(b[t].x,b[t].y,b[t].x+50,b[t].y+50)
s += 1
? s > 10
s = 1
u += 1
.
<