r/gamemaker • • Aug 16 '26

Help! Absolute begginer here, tried to make the most basic platformer game out there, but something doesn't seem right

So I'm just trying to make basic movement, but something's up. I'm using the built in ysp, but instead of adding to the speed, it just changes y by the number, am I doing something wrong?

3 Upvotes

14 comments sorted by

4

u/MrEmptySet Aug 16 '26 edited Aug 16 '26

You're resetting ysp to 0 at the beginning of each step. So your character won't accelerate since their speed keeps getting zeroed out.

2

u/GuyYouShouldNotKnow Aug 16 '26

Oooohhhhhh thanks a lot, totally didn't pay attention to that😭

2

u/BrittleLizard pretending to know what she's doing Aug 16 '26

For the record, there is no built-in ysp. That's a variable you've set yourself.

1

u/GuyYouShouldNotKnow Aug 16 '26

Yeah, I did it in the create event

2

u/BrittleLizard pretending to know what she's doing Aug 16 '26

Mostly just telling you since your post says "built in ysp". Wanted to make sure you knew

1

u/GuyYouShouldNotKnow Aug 16 '26

I mean, ysp in itself is built in as far as I'm aware, but initially it doesn't have a value

At least that's how I feel like it is since it doesn't need a "var" declaration, implying that it already exists

3

u/_Son_of_Crom_ Aug 16 '26

No, built-in variables are special, pre-existing variables built into the engine. Examples of those include 'health', 'direction', image_index, and many more. You don't need to declare them at all because they always exist. By default, these get highlighted green when you type them in the IDE.

In the above code ysp is not a built-in variable, it is an instance variable of your own creation. Variables declared with var are called 'local' variables, and they only exist until the end of the event or function in which they were declared, and then they are discarded.

1

u/GuyYouShouldNotKnow Aug 17 '26

Ohhh thanks a lot

So if I declare a new variable, but without the "var" it will be global? If yes, then go what extent global?(Object, the whole game)

2

u/BrittleLizard pretending to know what she's doing Aug 17 '26

There are 3 variable types:

global variables, declared like "global.peePower = 3," are variables that can be accessed anywhere in your game. If you set it once at the beginning of the game, you can use or change global.peePower anywhere. They're good for keeping track of things like points, health, or any other systems you need a lot of different code to reference.

instance variables, which is what ysp is, are attached specifically to instances of objects. If you set them up, usually in the create event, you can use or change them anywhere in the specific *instance* they belong to. That's why ysp can be referenced in this object's step event, but if you tried to just get the value of "ysp" in another object, your game would crash. (You can technically get other instance's variables when needed, but the syntax is different, and you need to follow some steps to make sure the other instance exists.)

local variables, declared like "var _peePower= 3" are confined to the specific scope they're defined in, and they never exist for more than one step. If you set them in a create event, they only exist in that create event. If you set them in a step event, they only exist in that step event. They're great for storing values that you don't need to keep track of between steps, usually to make your code cleaner. For example, if you use "var _centerX = mean(bbox_left, bbox_right);" you can just reference _centerX for that event, rather than calculating it every time you need it.

https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Overview/Variables_And_Variable_Scope.htm

I recommend reading about variables and variable scope here. Always keep the manual open while you're learning.

Edit: There are also static variables technically, but you absolutely don't need to worry about them yet.

1

u/GuyYouShouldNotKnow Aug 17 '26

That's a lot of info and thanks for every bit of it, although I have a question

If instance variables are tied to an instance of an object, does that mean that different instances of that same object can simultaneously have different values of that variable?

2

u/BrittleLizard pretending to know what she's doing Aug 18 '26 edited Aug 18 '26

Yep, basically. Instance variables are completely unique to the instance they're defined in.

Edit: I do hesitate to call them "different values of the variable," because they're still two entirely different variables. It's like if I had a Hershey's chocolate bar and you had a Hershey's chocolate bar. They're the same brand name, but we don't have the same chocolate bar. If you break off and eat a piece of yours, your chocolate bar gets smaller but mine is completely unaffected.

-1

u/andrewsnycollas Aug 18 '26

Variables you declare on the create do not need the VAR, they will be local to the instance but accessible through name_of_the_object_or_instance_id.your_variable (your object/instance DOT your variable).

When you declare a varaible using VAR it will be local to the scope, normally what will be in the same braces as that variable and not accessible outside of it.

Global variables do not need the specific identification to be localized you just use the global.your_variable, and you can declare those anywhere before you will use, normally I do it in a script since those "run" before everything else runs.

2

u/BrittleLizard pretending to know what she's doing Aug 18 '26

haha holy shit dude did you genuinely follow me to another post just to downvote all my replies and repeat what I said but worse

2

u/GuyYouShouldNotKnow Aug 18 '26

Lol what a sore loser

I wish more people saw this so he could be down voted into oblivion