Loop through a list of numbers?

For questions about using Classic.

Post » Wed Jul 16, 2008 12:41 pm

Hi! I've asked about this before in a diferent thread, but i can't remember where, and it didn't get answered, so i'm posting it again here in the right forum.

I'm creating an AI system that needs to check if a number of values exist in an objects private variable. At first i tried to code it in an event, but it ended up like this:


That is obviously not a solution. So i need a way to loop through these numbers and write them down somewhere else. The problem is that i can't find a place to write them down! The array can't be edited eccept with events, so i would still need like 20 of these events. An array that was visible where you could just klick a box and fill in the numbers would be a nice thing to ad in the future, but is there a soluton right now?

Does someone have any suggestions? I really really need a solution to this. Thank you for your time!

Jonatan
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Wed Jul 16, 2008 1:27 pm

I cant think of any and probably no solution other than creating event for every possibility, btw thats the curse of programing a lot of events...
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Wed Jul 16, 2008 7:05 pm

You could use a For loop and a Text object with numbers like:

1,7,19,257,380

then:

+ Always
: Set global variable 'found' to 0

+ For "i" from 1 to numtokens(Numbers.Text)
+ Private variable = int(gettoken(Numbers.Text, LoopIndex))
: Set 'found' to 1

From this point on, you can check the global variable 'found' to see if it matched.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Wed Jul 16, 2008 9:29 pm

Thank you very much Ashley! I'll try that out and return with information of how it turned out!
B
8
S
2
G
5
Posts: 744
Reputation: 3,288


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests