Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 too many variables?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cutecotton




PostPosted: 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? Rolling Eyes
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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


that assuming you know what arrays are.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
cutecotton




PostPosted: Tue Dec 24, 2002 6:22 pm   Post subject: (No subject)

*ahem* goes to find an array tutorial Embarassed Shocked

hmm...well i found an array tutorial and tried to understand it best as ic an..so from waht u posted..

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

u have 5 variables, and within them there's 2. What i dont' get is this line:

code:
picID(i,i2) := Pic.FileNew("image"+i+i2)


I undersantd the Pic.FileNew, and then u put hte filename in replacement of image, but wha'ts the +i+i2 thing?

[/code]
Tony




PostPosted: Tue Dec 24, 2002 6:29 pm   Post subject: (No subject)

http://www.compsci.ca/v2/viewtopic.php?t=71

though it was intended for Visual Basic.

But it explains what arrays are and how to use them.

In turing you declear arrays as

var arrayname : array first demention , second demention , etc of type

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




PostPosted: 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




PostPosted: 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




PostPosted: 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.

such as

button(x,y)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
cutecotton




PostPosted: 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

buttons (1) := Pic.FileNew ("lvl1a.bmp")
buttons (2) := Pic.FileNew ("lvl2a.bmp")
buttons (3) := Pic.FileNew ("lvl3a.bmp")
buttons (4) := Pic.FileNew ("lvl4a.bmp")
buttons (5) := Pic.FileNew ("lvl5a.bmp")

buttons2 (1) := Pic.FileNew ("lvl1c.bmp")
buttons2 (2) := Pic.FileNew ("lvl2c.bmp")
buttons2 (3) := Pic.FileNew ("lvl3c.bmp")
buttons2 (4) := Pic.FileNew ("lvl4c.bmp")
buttons2 (5) := Pic.FileNew ("lvl5c.bmp")
[/code]
Sponsor
Sponsor
Sponsor
sponsor
Albrecd




PostPosted: Thu Nov 10, 2005 2:49 pm   Post subject: (No subject)

Or you could just declare 10 variables... it's not really that many... and it doesn't matter because there's no limit.
do_pete




PostPosted: Thu Nov 10, 2005 2:52 pm   Post subject: (No subject)

yeah but array are more efficient
do_pete




PostPosted: Thu Nov 10, 2005 2:56 pm   Post subject: (No subject)

wow i just realized that this topic is from Tue Dec 24, 2002. you realize that was almost THREE YEARS AGO I'm with stupid
MysticVegeta




PostPosted: Thu Nov 10, 2005 3:02 pm   Post subject: (No subject)

yeah i was wondering how come no one pointed it out, anyways, instead of going buttons(1), buttons(2)
why not

PSEUDOCODE
code:
for s : 1..5
buttons(s) := Pic.FileNew("lvl"+intstr(s))
end for


Smart way to do it Wink
Cervantes




PostPosted: Thu Nov 10, 2005 3:44 pm   Post subject: (No subject)

Albrecd wrote:
Or you could just declare 10 variables... it's not really that many... and it doesn't matter because there's no limit.


You couldn't be more wrong. Wink
Compared to one, ten is a lot.
And you say there's no limit. If that's true, that makes your method even worse.
codemage




PostPosted: Fri Nov 11, 2005 9:01 am   Post subject: (No subject)

I'm sure cutecotton has either solved this problem or given up by now.
Cervantes




PostPosted: Fri Nov 11, 2005 4:54 pm   Post subject: (No subject)

codemage wrote:
I'm sure cutecotton has either solved this problem or given up by now.

Yeah, but Albrecd hasn't solved his problem. Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: