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

Windows Error - random image_rotate for random time

J

Jdown79

Guest
Hey guys, new to the forum.
the basic script design is for a random image_angle to happen on create

in create:
alarm[0]=irandom_range(room_speed*0.5,room_speed*1.5);
if (random(1) <= .5)
{
glassrotate = plus
}
if (random(1) >= .5)
{
glassrotate = minus
}

in step:
if glassrotate = plus
{
image_angle +=1
}

if glassrotate = minus
{
image_angle -=1
}

if glassrotate = stop
{
image_angle = image_angle
}

in alarm 0:
glassrotate = stop

I've ran over this a few times, and I'm not spotting any mistakes, but it still throws this error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_wall_glass_break_T_1:

Push :: Execution Error - Variable Get 100027.plus(100000, -2147483648)
at gml_Object_obj_wall_glass_break_T_1_CreateEvent_1 (line 4) - glassrotate = plus
############################################################################################

I'm hoping for a simple mistake that I've simply overlooked.
Thanks in advance.
 

jo-thijs

Member
Hi and welcome to the GMC!

You haven't defined plus, you should assign the variable plus a value.
The same for minus and stop.
I suggest you set plus to 1, minus to -1 and stop to 0.
 
J

Jdown79

Guest
Thanks,
so can my variable glassrotate only be defined by an integer?
e.g
glassrotate=1,2,0, etc
 

jo-thijs

Member
glassrotate can be defined by a real (number) or a string (text) or even some other things.
I'm thinking though you might want to use enmus here.
Using enums, you would do this in the create event:
Code:
enum rotatedir {plus, minus, stop};
alarm[0]=irandom_range(room_speed*0.5,room_speed*1.5);
if (random(1) <= .5)
{
glassrotate = rotatedir.plus
}
if (random(1) >= .5)
{
glassrotate = rotatedir.minus
}
 
A

Aura

Guest
Welcome to the GMC!

From what I can tell, you want to use strings.

Code:
if (glassrotate == "minus") {
   image_angle -= 1;
}
Read more about strings here:

http://docs.yoyogames.com/source/dadiospice/002_reference/strings/index.html

Note that for valid comparison, glassrotate needs to hold a string, not a real value. For instance, when you want the image to rotate clockwise, you'd set it to "plus" and the if statement shall do the rest.

If that doesn't help, please tell me what you are trying to achieve.
 
J

Jdown79

Guest
I replaced plus with 1, minus with 2, stop with 0,
if glassrotate = 1
{
image_angle +=1
}

if glassrotate = 2
{
image_angle -=1
}

if glassrotate = 0
{
image_angle = image_angle
}
but now it returns this:
action number 1
of Step Event0
for object obj_wall_glass_break_T_1:


Push :: Execution Error - Variable Get 100025.glassrotate(100000, -2147483648)
at gml_Object_obj_wall_glass_break_T_1_StepNormalEvent_1 (line 1) - if glassrotate = 1
############################################################################################

Compile finished: 9:45:27 PM

I'm really not understanding this one.

edit: I haven't implemented your script, but I'll try it. How would I reference it in the step event?

if glassrotate = rotatedir.plus {}
?

Thanks guys, just one of these issues I can't wrap my head around yet haha.
 

jo-thijs

Member
You don't guarantee glassrotate will have a value.
You should set it to the stop value before the rest of your code in the create event.

@Aura, yeah, that's probably better than what I suggested.
 
J

Jdown79

Guest
Haha wow, that was the fix.
Thanks a lot guys, impressive help.

On a different point, the next problem I need to tackle is a varied movement in a particular angle.
so imagine ten objects are going in the exact direction, is there a way to somewhat randomise it? while still going that way, veer off a little bit?
What would be my next bit of research to tackle this?
Thanks again guys.
 
J

Jdown79

Guest
@Aura I was aware that they needed to be declared, it was just a oversight I had made, thinking that I had mentioned glassrotate in create haha.
That problem is all fixed now, thanks
 

jo-thijs

Member
So, now you want to have 10 instances that rotate around themselves individually,
but rotate all in the same general direction, but with slightly different rotating speeds?
 
A

Aura

Guest
As for the question that you asked about randomisation of rotating speed, you can use random() in the Create event to generate a random rotating speed for each instance. Or irandom() if you want integers.

Code:
myspeed = random(5); //generate a random speed with a maximum limit of 5
And then use it while rotating.

Code:
if (glassrotate == "minus") {
   image_angle -= myspeed;
}
In the create event, you could determine a random action using choose() as well.

Code:
glassrotate = choose("plus", "minus", "stop");
I would strongly recommend using strings over numbers.

Also, for actual randomness, make sure that you call randomize() at the start of the game.
 
Top