September 11, 2015 at 4:11 am #2866
I figure this is the place to ask Game Maker questions, even though it doesn’t necessarily use coding. My games generally start as Drag and Drop, though I can convert to code.
So what is going on is I have a game whose player character can move in the standard eight directions; implemented by arrow-pressing events causing a “Jump to” relative points. For the sake of variety and depth, the character also has a boost. I considered various methods, but what I ended up doing was adding an event for pressing space bar; this turns a boost variable on for a short time, during which the aforementioned “Jump to” calls for higher coordinates than usual.
For the standard four directions; North, East, South, and West, it works perfectly. Yet for diagonal movement, something weird is going on; the boost works when the character is facing Northwest, but not for any other diagonal direction.
Any idea why?
September 12, 2015 at 10:14 pm #2870
I haven’t worked with Game Maker in years, but I would assume it has to do with the code (or in this case, drag and drop code) you have set up for the boost; something is different or not checked when it comes to the boost.
Do you have anything more specific regarding this? The one thing that comes to mind are checks as to which arrow keys are held down or released at the time of the boost, but I don’t quite know how you’ve handled it so far. Does standard diagonal movement work fine?
September 14, 2015 at 8:17 am #2875
Standard diagonal movement indeed works fine. Only with the boost does one direction alone work.
In actuality, “diagonal movement” is combined horizontal and vertical movement. Each direction is handled via events like <Up>, the first four actions in the events being
if Boost is equal to 0
jump relative to position (0,-3)
if Boost is equal to 1
jump relative to position (0,-6)
There are six more actions in every direction event, but they just control animations.
September 14, 2015 at 7:19 pm #2877
Based off of the information you’ve given, the only thing I can think of is that Boost would be set to 0 somewhere before the other keys are triggered. Where are all of your instances where Boost is set to 0? It sounds like the Up and Left arrows have priority over the boost change, at least.
September 17, 2015 at 9:22 pm #2882
Boost is set to 0 in the Creation Event, 1 in the <Space> Event, which also sets Alarm 0 to 35, and finally it’s set back to 0 when Alarm 0 rings. There is no affecting the variable in the directional events; they just check whether it’s 0 or 1.
If this helps, the boost technically works when moving any diagonal direction, but it can only be activated when the character is facing straight North, East, South or West.
September 18, 2015 at 7:18 pm #2884
If it can only be activated when facing North, East, South or West, then that means there is likely a problem with the code that activates the boost. What conditions are there for activating the boost, and what code is in place to allow or prevent a boost from occurring when Space is pressed?
September 24, 2015 at 12:36 am #2887
The “Press <Space>” event entails two variable checks:
If Boost is equal to 0.
If Fuel is larger than 1.
Start of a block
Set variable Boost to 1
Set variable Fuel (relative) to -2
Set Alarm 0 to 35
End of a block.
As you can probably discern, the event checks whether the Boost is off first, to keep from activating it repeatedly and draining all fuel.
Does that help?
September 24, 2015 at 6:54 pm #2888
It looks like the directional code and the Spacebar code are okay; I should probably ask, for clarification, what specifically is the problem? In the first post, you had said that the boost works for North, West, East, South and Northwest (but not the other 3 diagonal directions); in your second last, you said that the boost works in all 8 directions, but can’t be activated unless it’s in the standard 4. Does Northwest still activate the boost (based on the first post)?
Since the code you’ve shown so far looks like it works fine, the only thing I can think of: does your game require multiple buttons to be pressed at once? By that, I mean, how many keys are typically pressed during gameplay? i.e. 2 direction keys, Spacebar, a key for attacking, a key for something else, etc. There are some programs that have problems with too many buttons pressed at once. I can’t remember if that’s how it is with Game Maker and it’s a bit of a stretch, but based off of what you’ve shown, I can’t think of much more.
You must be logged in to reply to this topic.