Printing out hashtable values

For questions about using Classic.

Post » Sat Jul 11, 2009 2:27 am

Hey all,

I'm trying to go through the different areas of Construct and learn how they work. Right now I'm looking at processes. As you can see from the pic below, I'm simply populating a hashtable and then trying to print out each value. The hashtable is fine (there are only 37 keys), but when I do this last event:

For each key ... EditBox: Append text Hashtable.CurrentKey.Newline

instead of printing out the list once, it goes into an endless loop and prints the keys over and over...
I've looked at the different hashtable examples on here and it hasn't helped out. Any ideas?
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat Jul 11, 2009 2:43 am

Its hard to say with no cap but it you just have a for each with no other condition it will run every tick. you need to put a trigger once in there.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sat Jul 11, 2009 3:02 am

Thanks! I added a mouse click trigger and that solved the problem. I guess I don't fully understand why a For Each Key would run every tick, but I'm not that familiar with the event system yet. Once I get the hang of all this mundane stuff, hopefully I'll make a really cool game.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat Jul 11, 2009 3:39 am

All events are run every tick if the conditions are meant then the actions are done. For each is a condition and it has no other qualifiers so it will always run. If you add another condition to that then once Both of the conditions are meant it will .
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sat Jul 11, 2009 7:31 am

"For Each" is a loop. Think of your events like so:

[code:26vsc4mx]
1. Top of event sheet

2. Do some stuff

3a. Loop fifty times <--- this is your For Each
3b. Do stuff fifty times
3c. Go back to 3a fifty times

4. Do some more stuff

5. Go back to Top of event sheet
[/code:26vsc4mx]

The event sheet is read from top to bottom, and then starts over again. Since the whole event sheet itself is a loop, then the For Each is basically a loop within a loop. As Aeal said, barring any other conditions, a For Each loop will trigger each time Construct reaches it in the order of events.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Jul 11, 2009 2:44 pm

Thanks guys. That clears things up really well!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests