Local variables in repeat

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sincipient820
Posts: 25
Joined: Mon Feb 25, 2013 4:00 am

Local variables in repeat

Post by sincipient820 » Tue Aug 19, 2014 2:22 am

I have 8 local variables that I need to put into 8 corresponding fields. I'm wondering how I can do this with repeat. My code doesn't work but is as follows....

Code: Select all

locals svar1
local svar2 ----and so on until local svar8

put 5 into svar1
put 8 into svar2 --- and so on with different starting points

repeat with i =1 to 8
      put "svar" & i into tvar
      put "field" & i into tfield
      if (sFrame/10) is an integer then
         add 1 to tvar
         put tvar into field tfield of me
      end if      
   end repeat
the problem here is that the local variables don't appear to be recognized in the repeat. Rather it seems to treat it as a string resulting in "var1", "var2",....ect. So is there a way to identify multiple local variables in a repeat like this?

Thanks

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Local variables in repeat

Post by Thierry » Tue Aug 19, 2014 4:10 am

sincipient820 wrote:I have 8 local variables that I need to put into 8 corresponding fields. I'm wondering how I can do this with repeat. My code doesn't work but is as follows....
You can use arrays.

Code: Select all

put 5 into sVar[1]
put 8 into sVar[2]
.....
add 1 to sVar[ i]
.....
and you could try the modulo instead of sFrame/10 is an integer.

Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

sincipient820
Posts: 25
Joined: Mon Feb 25, 2013 4:00 am

Re: Local variables in repeat

Post by sincipient820 » Tue Aug 19, 2014 9:26 pm

Thanks that's the solution I was looking for.

Post Reply

Return to “Games”