0 Favourites

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

  • 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 --

    And this is the debugger showing the created cards' unexpected cardNumber variable (the one derived from the loopindex) --

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • 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.

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

    you need something like this

    so call & compare loopNumber in loop..

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,139
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,733
MPPlantOfficial's avatar
MPPlantOfficial
Unread hot topic
0 Favourites
[Plugin] Call Javascript
50 35,608
jailce's avatar
jailce