Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Can u Increment variable names

Author
Message
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 11th Apr 2004 13:45 Edited at: 11th Apr 2004 13:46
If I have some variables called:
Room1Health
Room2Health
Room3Health
Room4Health
Instead of duplicating lots of code which would be inefficient i would like to use the for next loop and use the loop value to change which room ie RoomAHealth.
Example

for A=1 to 40
if RoomAHealth=0 then somthing
more code
next A
Is this possible??

Thanks
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 11th Apr 2004 13:55
i'd make a type:
TYPE roominfo
Health
etc
etc
etc....
ENDTYPE

then an array:
DIM room(40) as roominfo

Then you can do it:
for A=1 to 40
if Room(A).Health=0 then somthing
more code
next A


Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 11th Apr 2004 14:44 Edited at: 11th Apr 2004 14:45
Thanks Blade for the response. I did think about using TYPE but didn't as at the time my game was quite small. However i've taken you advice and decided to use the versatility that TYPE will give me to make my game bigger.
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 12th Apr 2004 13:58
I though i got away without the need to increment variable names but it looks like i'm going to need it after all. I have got about 12 .x files of buildings that i have created. Loading these together with light map and other features means that it will be more efficient if this is done within a loop.

Just cus i'm a beginner doesn't mean i need to be sloppy. Am i right or am i right.

Thanks
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 12th Apr 2004 17:43
Sometimes you have to learn a new technique. DB does not allow for mangled variable names. You have to use an array of integers or an array of types with an integer inside it to store your object IDs.

For example:



Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 12th Apr 2004 19:15
Thanks Zircher. Exactly what I was after. I have been using Arrays and type throught my game but
Quote: "fn = "building"+str$(a)+".x""
part wasn't entering my thick skill. Probably Jack D had something to do with it.

Login to post a reply

Server time is: 2024-09-22 04:33:59
Your offset time is: 2024-09-22 04:33:59