Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
V3ndetta

What is a good way to loop this array ?

Question

I have a peasant patrol script that moves between points, and once he finished moving to the last point(index) in the array he needs to go backwards, so doing a for loop and setting the values to decrease after each time the peasant arrives at an index point seems to be the way to do it, however I don't know how should I handle the looping backwards of the function. Should I use a try and catch, to go from the highest index point towards the lowest, and inside that another catch going towards the highest value again, or is there a better method I can use? I also thought of checking to what index the peasant moves, and when it arrives, if it's the last one in the array, loop backwards. Thanks in advance.

 

Please login or register to see this code.

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

to make a infinite array you can simply do

 

x=0;

for (x<1){

do what ever you want here...

 

}

 

it can go to infinite. (or at least on desktop apps it does

Share this post


Link to post
Share on other sites

  • 0

If i understand correctly, your wanting to ping pong waypoints correct? I.e. p0-p1-p2-p1-p0 and repeat the process.

 

i believe (don't quote me on this) you can ping pong a loop like this:

 

var pong : int;

for(var ping = 0; ping < 5 && ping >= 0; ping += pong)

{

if(ping == 0) pong = 1;

else if(ping == 4) pong = -1;

yield MoveToTarget(ping);

}

 

but just keep in mind if you try to get too crazy with loops, save you progress really frequently bc your probably gonna lock up your pc several times

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...