Making a loop - pulling my hair out

Hi I'm trying to make a box in an elevator move up and down.

the box has 5 positions (called boxpos 1,2,3,4,5)

i'm trying to make a loop with a timer, so every 1 second it updates the attribute boxpos = boxpos + 1

each box then check if boxpos = 4 set alpha to 100.

thats working fine.

My problem is - i want my loop to change direction when boxpos = 5 then I want it to set boxpos = boxpos - 1 until boxpos = 0 then i should +1 again.

How do I do that? I have an attribute called boxDirection, but its not working?

Thanks for your help.
Anders

Comments

  • -Timo--Timo- Member Posts: 2,313
    if boxDirection = false
    do
    every 1 sec change boxpos to boxpos+1
    else
    every 1 sec change boxpos to boxpos-1

    if boxpos = 5
    do
    change game.boxDirection to true

    if boxpos = 1
    change game.boxdirection to false

    this should work ;)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2013

    @andersduus

    Hi Anders, hopefully the attached test file will help you.

    P.S And welcome to the Forums. :-)

    P.P.S typing while @timolapre1998 was replying.
  • andersduusandersduus Member Posts: 12
    @timolapre1998 thanks i'm pretty sure that what's I've been trying to do. Where do you place the code - on the box actor or background?

    @gyroscope thanks a lot. A whole lot more nested rules and times than I had - seems like the way forward. I'll let you know if it worked for me :-)
  • andersduusandersduus Member Posts: 12
    one stupid question - how do I copy code from one game salad instance to another?
  • FallingBoxStudiosFallingBoxStudios Freelance Graphic Designer Member Posts: 822
    one stupid question - how do I copy code from one game salad instance to another?
    You can't :( not from different projects, if its the same project then you can ;)
  • andersduusandersduus Member Posts: 12
    thanks @RockitGames

    @gyroscope it's so odd. when I recreate you code in my project the counter does not stop at 5, but continues....
  • -Timo--Timo- Member Posts: 2,313
    here is how I should do it. (same way as in my other comment)
    https://www.dropbox.com/s/wv1p6285bd3waqa/int updown.gameproj.zip
    this is probably a little bit easier and you can just typ is over? ;)
  • allc1865allc1865 Member, PRO Posts: 777
    one stupid question - how do I copy code from one game salad instance to another?
    You can click on on the rule > command C (mac) or CTRL C (windows) > go into the other game file, click in the empty white space where you put your rules > CTRL V (windows) command V (mac). Or you could click on the rules and ALT (Option) drag it into another window. To select multiple rules, click on the rules and hold down Shift while you select more...

Sign In or Register to comment.