Posted: Tue Dec 24, 2002 5:38 pm Post subject: too many variables?
hi everyone, what i'm trying to do with my program is i'll have 5 litlte buttons, and the buttons will change when the user runs their mouse over it. So let's say for button 1 i have 2 variables for it, one contains the pic b4 the mouse is run over, the 2nd contains the pic that will be dispalyed when the mouse is over it.
Now my question is, i'll have to do that for all 5 buttons, so does that mean i'll have to declare 10 variables? since i'll need 2 for each button? that seems to take a lot of...well variables and i don't know if there's a limit of the amoutn of varaibles i can declare.
is there a more efficient way of doing this? or will i really have to declare a variable for every single pic i put on screen?
Sponsor Sponsor
Tony
Posted: Tue Dec 24, 2002 6:20 pm Post subject: (No subject)
try using arrays.
code:
var picID : array 1..5, 1..2 of int
for i:1..5
for i2:1..2
picID(i,i2) := Pic.FileNew("image"+i+i2)
end for
end for
But it explains what arrays are and how to use them.
In turing you declear arrays as
vararrayname : arrayfirst demention , second demention , etc oftype
where dementions are ranges such as 1..10 (1 to 10) and work same as in for loop
type is string/int/real/etc
array variable is accessed using
arrayname(1st demention , 2nd demetion)
as in arrayname(5,2)
cutecotton
Posted: Tue Dec 24, 2002 6:36 pm Post subject: (No subject)
ooo i get it...*kinda* have to test it out myself to se eif it works..will post back in a few minutes ^^
cutecotton
Posted: Tue Dec 24, 2002 6:43 pm Post subject: (No subject)
right..so now what do i do if i wanna use the variables and make them show up?
sof ar i go:
code:
var buttons : array 1 .. 5, 1 .. 2 of int
for b1 : 1 .. 5
for b2 : 1 .. 2
buttons (b, b1) := Pic.FileNew ("lvl1a.bmp")
end for
end for
loop
Mouse.Where (x, y, b)
if x >= 60 and x <= 212 and y >= 130 and y <= 173 then
Pic.Draw (buttons, 60, 130, picCopy)
else
Pic.Draw (b, 60, 130, picCopy)
end if
end loop
so in my Pic.Draw (buttons, 60, 130, picCopy)...i don't know what i shoudl put in replacement of my "button"?
Tony
Posted: Wed Dec 25, 2002 12:04 am Post subject: (No subject)
it should be
button(1,1) for first button, 1st view
button(1,2) for first button, 2nd view
etc...
button(5,2) is 5th button, 2nd view
instead of numbers you can use variables to make it easier.
Posted: Sat Dec 28, 2002 10:23 pm Post subject: (No subject)
hmm yeah, but then each button woudl have a differnet file. Example (the goal here is that i have 5 levels, and the user select which lvl they want. So lvl 1 would have 2 pics, but ecah lvl's pic is differnt, cuz the pic woudl say lvl 1 for lvl1, lvl 2 for lvl 2, etc)
So what i did was i used arry to delcare all the variables, and then i just took ecah one and idenfied it. So i have something like
code:
var buttons : array 1 .. 5 of int
var buttons2 : array 1 .. 5 of int