Random Function returns 0 occasionally

0 favourites
  • 3 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi all, the problem in a nutshell is that sometimes the following function returns 0 (according to the debugger, either it's returning 0 or something that's not a valid key code)

    Essentially what I want to happen is:

    > call the function "SpawnLetter"

    set tmp = 65

    tmp = random(65, 91) // 65-90 is the range of letter keycodes

    if tmp not in use, return tmp

    if tmp in use, recursively call

    Here is a picture of the Function in the event sheet

    The game (One Thousand Hands) is attached as a single capx file (I apologize in advance when you see my terrible structure!)

    If there are any parts that aren't clear (due to my naming and such) let me know!

    Also if you want PM me what you think of the game, it's not really self explanatory atm but if you're willing to work it out it's definitely playable!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The random function definitely isn't the issue here, which means event 111 never runs. Your problem stems from event 112 where you're calling the function again but not returning anything afterward. Just because your inner function returns a value does not mean that the calling function inherits that return value.

    To fix this, instead of calling your function again in event 112, simply set the return value to Function.Call("SpawnLetter") which will call and retrieve the return value from your function.

  • Thank you so much!

    I've been playtesting for 5 minutes and no problems so far! This bug has been on my to do list since I started making the game ^^

    Thanks again, especially for the quick and concise respone :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)