(SOLVED)Some questions

ebi_nebby

Member
Hi there, I'd like to ask some questions:

When we make a new object, does something always need to be written in create? (Sorry I am so new to this) for example, I was trying to create a simple space shooter ish game, and I got a sprite to move around and such, however the "power up" does not move around.

for the power up, I set an alarm (I wanted it to randomly move around because I eventually wanted the player to be able to get power ups while avoiding enemies
alarm[0]=60

and in the alarm, I wrote
if (alarm[60]<0)
{
alarm[60]=60
}
direction=irandom_range(0,359)
speed=2

and in draw, I wrote
repeat (10)
draw_sprite(sprite1,0,100,100)

Because I wanted to have 10 powerups moving randomly.

Thank you,
Ebi

(EDIT)
thanks everyone for the help :D
 
Last edited:

ophelius

Member
When we make a new object, does something always need to be written in create?
You don't need to have a Create event, but typically that's where you declare all the variables the object will have access to.

and in the alarm, I wrote
if (alarm[60]<0)
{
alarm[60]=60
}
The If statement is redundant, GM calls the alarm for you when it reaches 0, so no need to check inside the alarm if it's triggered

repeat (10)
draw_sprite(sprite1,0,100,100)
Here you're drawing the same sprite 10 times at the same location, this does nothing but draw sprites on top of each other

The power object won't move unless you give it code to move, change its x and y variables over time.

Apart from that, the code here is not clear enough what's going on. Is this code coming from the power up objects? How are you creating these power ups?
 

ebi_nebby

Member
Ahh okay! Thanks for letting me about the create events.


I also now understand about writing basically the same code- thanks for that too!

So if an object needs a code to move, would that be written in a step? and can it be something like move_random?

and these codes are coming from the power up object.(it's basically a space shooter game lol, the power up is like a sun, while the player is a cherry collecting sun while avoiding... whatever cherries avoid? lol)

so for the power up, I made it into a object (ob_sun) and the codes I provided above were what I put in it.

Hope this kind of clarifies things!
 

ophelius

Member
So if an object needs a code to move, would that be written in a step? and can it be something like move_random?
Yes, the step event is ran every frame, and each object have built-in variables like x and y that you can change how you want (move_random() is just 1 example of a way to change the x and y variable).

Objects can create other objects, using functions like instance_create(), so if your powerup object wants to create other objects, you would use that.
There's plenty of other instance functions, check the manual for more details.

I would start with basic tutorials and check the manual, it sounds like there's a few things you need to learn before tackling this.
 

TheouAegis

Member
So if an object needs a code to move, would that be written in a step? and can it be something like move_random?
Yes and no and maybe. Code for moving can go in the Create event or on the Step event. Or it can go in an alarm event. Or in a timeline.

move_random is for "teleporting". And ot would be seizure-inducingly rapid teleporting. Typically for random movement you'd use motion_set() in the Create event or alarm event, using irandom(360) for the direction argument.

It takes 5 seconds to compile a test project. Just test everything out for yourself.
 
Dunno if I missed something, but you have:

alarm[0]=60

but in the alarm event, if you intend for it to reset itself, you have:

if (alarm[60]<0)
{
alarm[60]=60
}

I know other users have pointed out that there is no need for an alarm to check its current state, when its actually running that process to begin with. What I would point out is that it ought to be this (assuming its not a typo)

alarm[0] = 60;

Since that is the alarm you want repeating (?), and it is the one you are doing this in.
 
Top