Loop question

Discussion and feedback on Construct 2

Post » Fri Apr 27, 2012 10:17 pm

Looking on how to refine a bug to send it to "bugs" forum, I found this strange loop behaviour:

(see example https://www.apagada.com/varios/tictactuc/tictacbug2.capx )

For (N in 0 to 8){
.. Create object X
.. Pick instance N {
.. .. Set property blah, blah, blah.
.. }
]


No object gets the blah, blah, blah property. If you use, instead:
For (N in 0 to 8){
.. Pick instance N {
.. .. Set property blah, blah, blah.
.. .. Create object X
.. }
]

Then all objects get the property, as intended.


At the other hand,

For (N in 0 to 8} {Create object X ...}
For each object X {Text.append "Blah blah blah"}

does nothing with text.

I don't really understand how to use loops in an event-ruled programming language. In fact, I use to add a condition like
"loopindex(N)>=maximum value" inside each loop to ensure some events execute after the loop.

Can anyone explain me how to place events in the loop?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Fri Apr 27, 2012 11:46 pm

I suppose it fails because of "For each object X" or the pick-condition.
The sprite actions in a loop pick the created instance without any special pick event.

forLoop - example
Joe72012-04-27 23:50:43
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Sat Apr 28, 2012 6:21 pm

The issue you're having is with how newly created objects are picked.

Here is an outline of the rules:http://www.scirra.com/forum/picking-problem_topic41776_post257714.html#257714
B
79
S
24
G
54
Posts: 4,750
Reputation: 40,763

Post » Mon Dec 31, 2012 3:03 am

@Joe7,

Since the topic is looping. I would like to ask a help regarding my problem on looping.

I have a php function and I request the php file to fetch data and load in the listbox. the php file is working and it return value on the listbox.
The problem that I encounter is only one data is return on the listbox what I need is it should load all the data. below are the files that I am working on.
https://www.dropbox.com/sh/097xa30dcgmnlzt/cuv9YRl7Ky

Please guys I need help on this issue.
B
16
S
2
Posts: 21
Reputation: 869

Post » Tue Jan 01, 2013 4:42 pm

@aragon
Instead of digging very old unrealated topic you should create your own really (: (it's not because someone mention loop that it's related to your issue)
Now if you want an answer we need to be able to open your capx, and since it's full of third party plugin, it's a real pain (I don't want to install plugins)
If you can't really get rid of them, try posting a screenshot of your event sheet.Yann2013-01-01 16:43:04
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 02, 2013 2:14 am

@Yann,

Thank you for your reply, this is the screenshot of my event.
https://www.dropbox.com/s/2engpjf9le6vph2/listbox.png

I am badly needed a solution for this issue :(aragon2013-01-02 03:29:47
B
16
S
2
Posts: 21
Reputation: 869

Post » Wed Jan 02, 2013 2:49 pm

@aragon
I've never used the ComboBoxListBox plugin before so I might be wrong
Nevertheless, you're not using the proper parameters in the tokenat() function
What you probably want to do is:[code]ComboBoxListBox: Add: tokenat (AJAX.LastData, loopindex, "|")[/code]I don't really know what you want to do in event 3 since your condition is more or less the same as saying "if a = a" or event "Every tick" since it's always true and your second action is overwriting the first one.

And also, since I've seen your php implementation, I think you have a trailing | at the end of your list, so a blank token. You might need to address that.Yann2013-01-02 14:51:01
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 02, 2013 6:14 pm

Locking this topic, if you have more questions, create a new one as said before.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795


Return to Construct 2 General

Who is online

Users browsing this forum: 99Instances2Go, Artpunk and 13 guests