• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

instance_create_depth isn't working how I think it should?

C

ChaoticNeutral

Guest
In theory this script:
Code:
do
{
    instance_create_depth(irandom_range(96, 864), 32, 100, obj_calvinButton)
    count++
}
until(count = 5)
should create an instance of obj_calvinButton randomly five times along the top of the screen. But it's not. Could someone explain this to me?
 
C

ChaoticNeutral

Guest
What is it doing? What's not working about it? Is there something at a lower depth that could be blocking the calvin buttons?
The only thing that it's doing is showing up ONCE. It's called by obj_calvin with:

with (obj_calvinButton)
{
image_alpha = 100
event_user(0)
}
and there isn't anything that is blocking the instances out
 
So only one button is showing, instead of the 5? Does the button have code that draws it in a specific spot? Is there anything that would move the buttons? What's in the button's user event 0? Does the button have a parent object? Is count set to 0 before the loop starts?
 
C

ChaoticNeutral

Guest
Also, where is count set, and reset?

This is the ideal place to use the debugger as well. Probably a single break point and walking through it once would show you the issue. SeeDebugging with GMS2.
count is set in the create event simply with:
count = 0
And thanks for the debugging suggestion I'll get right on that!
 
C

ChaoticNeutral

Guest
So only one button is showing, instead of the 5? Does the button have code that draws it in a specific spot? Is there anything that would move the buttons? What's in the button's user event 0? Does the button have a parent object? Is count set to 0 before the loop starts?
one at a time. 1. no, it is always random 2. no, that area is all empty space 3. user event 0 is the script that's not working 4. no parent object 5. the count is set to 0 before the loop starts
 

samspade

Member
Seems like your code is good so probably there is something else interfering. I would recommend the debugger.

I'd also recommend not using depth in GMS2. It's designed to use layers. And depth also uses layers, it just creates them automatically which makes it harder for you to use all the features that layers offer. But that likely wouldn't affect this problem.
 
C

ChaoticNeutral

Guest
Seems like your code is good so probably there is something else interfering. I would recommend the debugger.

I'd also recommend not using depth in GMS2. It's designed to use layers. And depth also uses layers, it just creates them automatically which makes it harder for you to use all the features that layers offer. But that likely wouldn't affect this problem.
Okay so after running the game through debug mode, I found out that multiple instances of obj_calvinButton were being created but they were all placed at the same coordinates. Seems as if the irandom_range(86, 864) wasn't working as I thought it would. In short: They're all being created in the same place. And I'll remember to use layers from now on thank you.

Edit: I was just looking through the manual and it says that:
"NOTE: This function will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to make debugging code a far easier task. To avoid this behaviour use randomize at the start of your game."
So it's chose a random number ONCE and has been using it multiple times. Thank you for your tips and advice!
 
Last edited by a moderator:
Top