[Solved] How do I pass loopindex to a Function Call?

Get help using Construct 2

Post » Sat Sep 24, 2016 6:14 pm

I'm making a Texas Hold 'Em style Poker game. I'm having difficulty with a function which is called from inside a loop, whose intended role is to make the cards to deal to the players. When I pass loopindex to the function as a parameter, and use that parameter to set an object's variable (one created in the function), it ends up being erroneous (-1).

Here's the loop and function from the event sheet with arrows pointing to the relevant bits --
Image

And this is the debugger showing the created cards' unexpected cardNumber variable (the one derived from the loopindex) --
Image
Last edited by paladin on Sun Sep 25, 2016 7:34 am, edited 1 time in total.
B
9
S
1
Posts: 12
Reputation: 448

Post » Sat Sep 24, 2016 7:20 pm

While I haven't looked into it in depth, I see a wait in there. Waits in loops are a classic recipe to break everything.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Sat Sep 24, 2016 8:28 pm

One thing i need to tell you that you should start naming the loops and 2nd can you just place a sprite that would just hold variable and place the loopindex onto it and then use that variable for the parameter? And also I thought that loopindex only work within the loops since loops are dynamically always changing never static.
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Sun Sep 25, 2016 1:56 am

if you try somethig simple ..you will see that loopindex don't wait..
Image

you need something like this
Image
so call & compare loopNumber in loop..
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sun Sep 25, 2016 7:33 am

korbaach wrote:if you try somethig simple ..you will see that loopindex don't wait.. so call & compare loopNumber in loop..


That did the trick. Interestingly, if I added to the counter before the wait, all of the cards had the max value of the loop... whereas placing it after it worked as expected.

Thanks for your help guys :D
B
9
S
1
Posts: 12
Reputation: 448


Return to How do I....?

Who is online

Users browsing this forum: dop2000, LunaticCat, matriax and 8 guests