easy fix I'm sure just can't seem to see it

W

Wild_West

Guest
well so much for me thinking I'd gotten all the basics down lol

But yeah I don't know why this isn't working and I'm only asking since I've tried everything else but my Bat enemy isn't responding to it's creation code variable check.

I just want to change whether they fly side to side or up and down based on a variable defined in the creation code of the room editor. You know when you place an object in the room and right-click it to go into creation code.

This is The code in the bat's step event (since for some reason defining the setup in create event doesn't work, like I saw in a tutorial, may have been an outdated version of GM , don't remember)


But yeah anyway, the bat with the Y axis flight pattern isn't moving in both the Y directions just whatever the first value is. If I take it out then the bat moves to the left like the one with the X axis value which it shouldn't be since nothing is telling it to.

In Create

image_speed = .3;
speed = 3;

in Step

//X axis flight pattern

if(flight_pattern == "X axis") and (direction = 0) and (x > xstart + 400)
{
direction = 180;
image_xscale = -image_xscale;
}

if(flight_pattern == "X axis") and (direction = 180) and (x < xstart - 400)
{
direction = 0;
image_xscale = -image_xscale;
}

//Y axis flight pattern

if(flight_pattern == "Y axis") and (direction = 90) and (y < ystart - 200)
{
direction = 270;
image_xscale = -image_xscale;
}

if(flight_pattern == "Y axis") and (direction = 270) and (y > ystart + 200)
{
direction = 90;
image_xscale = -image_xscale;
}

and then just set the flight_pattern X or Y in the creation code after I place the in the room right? Any idea what I'm not seeing that I screwed up because I've done more complex than this with creation code before and it worked fine.
 
S

Supercoder

Guest
It could be because of the "direction" if statements. The default for the variable "direction" is 0.
 
W

Wild_West

Guest
It could be because of the "direction" if statements. The default for the variable "direction" is 0.
Oh I actually didn't know that or even think of it lol
Of course it's 0 everything starts at 0. ugh I feel so dumb.

Okay but if I set the direction manually using the y axis variable the Y axis bat will go up but when it reaches the point it's supposed to fly back down it flickers in place, switching from 90 to 270.

even though I just copied the X axis stuff for it.
so I can't seem to grasp why X works and Y doesn't.

I only have like 7 more enemies to go after this one so I guess my haste to finish is clouding my judgement xD
 
S

Supercoder

Guest
Hmmmm... I'm not seeing anything wrong with your code... Is there any other code that might be relevant? Any other place where the direction is being changed?

edit:
Where are you setting it manually? In the step event?:pickle:
 
Last edited by a moderator:

Weird Dragon

Wizard
GMC Elder
well so much for me thinking I'd gotten all the basics down lol

But yeah I don't know why this isn't working and I'm only asking since I've tried everything else but my Bat enemy isn't responding to it's creation code variable check.

I just want to change whether they fly side to side or up and down based on a variable defined in the creation code of the room editor. You know when you place an object in the room and right-click it to go into creation code.

This is The code in the bat's step event (since for some reason defining the setup in create event doesn't work, like I saw in a tutorial, may have been an outdated version of GM , don't remember)

...
Something you need to know about the creation code in the instance:
That creation code is performed after the normal create event.

Reference:
  • Creation Code: This option opens up a code editor where you can add code into the specific instance that you have clicked on. This is a very powerful feature that allows you to further change individual instances of objects and so give several instances different values or variables to change their behaviour. This code is run after the normal create event, but before the room start event (see Using GameMaker: Events for the complete order of events).
Further reading:
https://docs.yoyogames.com/source/dadiospice/001_advanced use/more about rooms/index.html
 
W

Wild_West

Guest
Hmmmm... I'm not seeing anything wrong with your code... Is there any other code that might be relevant? Any other place where the direction is being changed?

edit:
Where are you setting it manually? In the step event?:pickle:
actually yes, I saw that mistake after I stopped trying to rush it lol

setting my movement to hspeed or vspeed = whatever in the step event was messing up the ability to move any other way.
I know I wasn't using h or vspeed before but I was just trying everything out of frustration.
stupid I know but I got there eventually :p

so now I just need to get the actual creation code to run and it'll be fine.
 
W

Wild_West

Guest
Something you need to know about the creation code in the instance:
That creation code is performed after the normal create event.

Reference:


Further reading:
https://docs.yoyogames.com/source/dadiospice/001_advanced use/more about rooms/index.html
Okay that's good to know so I was just using the commands in the wrong order.
I tend to avoid the manual just because I learn better visually but I should really start documenting the stuff in it.
The math was what I mostly struggled with so I figured I didn't need anything else from the docs, since I was good with the Gml, but the order of events was something I'd forgot about as far as creation code and create event went.
Thanks for the help
 

Yal

šŸ§ *penguin noises*
GMC Elder
Yeah, I'd put that code in the Room Start event instead, and it'll run after the creation code you give the objects is run.
 
Top