Axe Software Forums
  Quest Developer Forum
  a var. in a var.


Author Topic:   a var. in a var.
sweetguy posted 18-10-2001 20:11 GMT     
how would you put a var. in a var.
this would make my code in one part so much shorther in the for i have but it would work unless i can do this here let me post it to see if you can figure an easier way

set numeric <x; 0>
for <x; 1; 4; 1> {
if is <#per(%x%)#;none> then {
set string <per%x%;#player#>
set string <new pos;per%x%>
do <in player>
}
}

that's how i have it set up right now but this part:

if is <#per(%x%)#;none> then {

i can't get it to work can you please help me out.
thanks

Computer Whizz posted 18-10-2001 21:50 GMT          
Well, you can use arrays in a similar manner "#variable[index]#" where the variable "index" is a numeric variable. Since it is reffering to an array then there's no need for the %'s.

But this is only good if you have pre-declared your variable array...

So, what you have to do is just have the array and go from there! One thing though - why do you have this part:

quote:

set string <per%x%;#player#>
set string <new pos;per%x%>

When you can just put:

quote:

set string (or set) <new pos; #player#>

??

Computer Whizz

sweetguy posted 19-10-2001 07:58 GMT          
i guess you don't get what i mean watch i'll breck it down for you:


'set x to 0 --- x=counter and placer for player

set numeric <x; 0>

'to do the proc 4 times useing x as the main way change the place

for <x; 1; 4; 1> {

'if place one = none then put player here
'on seond time
'if place two = none then put player here and so on

if is <#per(%x%)#;none> then {

'just set the player in place

set string <per%x%;#player#>

'to remeber where the player is so i can set his stats in the write place

set string <new pos;per%x%>

'here i get x to 4 to end the for but if the place was taken then it advances to the next

do <in player>
}
}

so looking at that you can see why i need to be able to have a var. in a var. i have it done in hard code:
check if place one empty then do this
check if place two empty then do this
blah blah

but that would just show i am a sloppy coder and will get very confused if i need to cahnge something laater on. thank for your help in advance.

if you still confused tell me and i'll just post the old code which is about 20 to 25 lines (i think)

Computer Whizz posted 19-10-2001 21:26 GMT          
As I said - you can use arrays..... just use an array up to 4! (really it should be up to 3 cos it includes 0... unless you want 5 peps!)

Anyway, why would you want to set the variable "new pos" to the player?
Everytime it goes through the for it'll reset the variable! So you won't get anywhere!

Computer Whizz

sweetguy posted 20-10-2001 03:06 GMT          
ummmmmm ok. yeah i know the array but you con't do the array in a rof cuse you need to chage the var but you i guess you can;t do it in quest. anyways forget about it. i just did it a diffrent way. oh and i need the var. new pos to rebmeber the place of the player so i dodn't have to test for it. (i gona use it to set stat.s but you can see it here.
Alex posted 20-10-2001 12:38 GMT          
for <i; 1; 12> {
set numeric <numbers[i]; %i%>
}
Computer Whizz posted 20-10-2001 14:41 GMT          
Right - sweetguy.
You can access an array through a for, using Alex's example above!

And just one note - Everytime the for loops it will overwrite the "new pos" variable.... so you only get the last character in "new pos" which seems to me to be useless!

You might as well have it outside the loop....

Computer Whizz

sweetguy posted 20-10-2001 18:21 GMT          
yeah.i see what you mean about the array now. but it still won't solve the prob. i had there cuse i need the valure of per 1 2 3 and 4 that's why i need the var in a var. thing. but i just did it a diffrent way a few more lines but it still not to bad.

about the for it will only go theough once cuse in the <in player> proc i have it seting x to 4 so that way it will only write in new pos once. if not i would have the same peoron in all 4 places but the in player proc is what i use to set all the stats and then set x to 4 - ending the loop

Computer Whizz posted 20-10-2001 18:59 GMT          
No!
The for will ALWAYS go through 4/5 times because you have said to it:

count from 1 to 4....
do the following after every count
go back up and actually DO the count

and to get the value from an array you just put #per[1]# or #per[2]# or #per[3]# or #per[4]# and you'll get the value just like any other variable!

Computer Whizz

sweetguy posted 20-10-2001 22:01 GMT          
yeah ok i see, what you saying, my bad.