Random Function returns 0 occasionally

Get help using Construct 2

Post » Tue Oct 21, 2014 9:54 pm

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

Image

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!
You do not have the required permissions to view the files attached to this post.
B
8
Posts: 12
Reputation: 338

Post » Tue Oct 21, 2014 10:50 pm

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.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Tue Oct 21, 2014 11:35 pm

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 :)
B
8
Posts: 12
Reputation: 338


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests