GML Assistance With Code Explanation

DayCamp

Member
Hello all. I am currently following a Udemy course for Gamemaker 2 called "How to make a Tile Based Platform" and am hoping someone can further breakdown the meaning of the code I have written. Although I understand the basic logic of many Gamemaker perimeters, I am still new and learning.

In the player object, I have a Create Event and a Step event (both below). I understand what is happening with lines 10 through 13 of the Step Event, but lines 16 through 28 is where things get confusing for me. Line 16 in particular, I am struggling to grasp the logic of "hsp += (right - left) * walk_spd;". Let me know if additional details are needed.

1593386875525.png 1593386958234.png
 

FrostyCat

Member
Line 16 isn't difficult if you would just spend some time evaluating the other 3 possibilities for left and right (left 0 right 0, left 1 right 0, left 1 right 1), and neither are the rest of the lines down to line 28 if you would just look up the function names in the Manual and examine their behaviours at various values of hsp.

There's a reason why computer science students are taught to draw value tables. Not drawing one physically or mentally means you can't read code on your own.
 

DayCamp

Member
Well, they're difficult for ME, not you.

Also, what function names are you referring too that are shown in the images? Can you specifically tell me what function names I can look up in the manual that are in the pictures I posted?

Lastly, our intelligence levels on this subject matter are clearly much different. I am not sure what you mean in your first sentence.
 

FrostyCat

Member
Also, what function names are you referring too that are shown in the images? Can you specifically tell me what function names I can look up in the manual that are in the pictures I posted?
The function names are lerp, abs, sign, and min. Go into the Manual as I instructed, click the Index tab, look up the article entry for each of them, and read it carefully.
I am not sure what you mean in your first sentence.
I mean manually calculating the value of (right-left)*walk_spd and then discerning the underlying pattern.

walk_spd is always fixed at 1.5, so only left and right can vary. There are 4 different combinations of left and right values:
  • left 0, right 0: (0-0)*1.5 = 0
  • left 0, right 1: (1-0)*1.5 = 1.5
  • left 1, right 0: (0-1)*1.5 = -1.5
  • left 1, right 1: (1-1)*1.5 = 0
At this point you should realize that line 16's purpose is increasing the horizontal speed by 1.5 in the net direction indicated by the left/right arrow keys.

This is how programmers evaluate the functionality of code. They propose input states into a piece of code, run through the lines themselves, produce a theoretical output, and compare that to an expected output. Keeping track of this means value tables. Being new does not give you an excuse to skip this.
 

EvanSki

King of Raccoons
"hsp += (right - left) * walk_spd;"
hsp is acting as a check if the palyer is pressing a button
right - left is making sure that only one key is allowed to do any movement (1 - 1 = 0)
hsp += (1) * walk_spd this is making the check we did equal the speed we want to walk at

hsp acts as a flag (think bool (True or False)) and if it is true its value is the walk speed

You then go on to use the walk_speed to determine movement

All very basic stuff a look in the manual (F1) would tell you
Very serious and strict programmers such as frosty cat would expect you to check the manual thoroughly before posting a question
 
Last edited:

DayCamp

Member
Jesus. Yes sa masta sa

I am so sorry that I disappointted the great frosty

I'm not a computer, so isn't it possible we allhave a different retention rate. All I hear are presumptions to what I have and have not done. But neither of you know what I have and haven't done. A measured repsponse would be to ASK if I've read the manual and to consult it if I haven't Addittionally, the specifics I was asking in my posts were for the local variables and how they work logically. THAT"S IT. HOW DO THEY WORK LOGICALLY. Didn't ask for anything else. You both answered that, yes, but wanted to fit your mansplaining in first.
 

EvanSki

King of Raccoons
I'm not a computer, so isn't it possible we allhave a different retention rate. All I hear are presumptions to what I have and have not done. But neither of you know what I have and haven't done. A measured repsponse would be to ASK if I've read the manual and to consult it if I haven't Addittionally, the specifics I was asking in my posts were for the local variables and how they work logically. THAT"S IT. HOW DO THEY WORK LOGICALLY. Didn't ask for anything else. You both answered that, yes, but wanted to fit your mansplaining in first.
Just answering your question and explaining Frosty's behavior, I really dont care if people look at the manual or not

Just a warning though, being sassy wont get you very far on the site, a lot of members are friendly and helpful others are straight to the point and serious like Frosty
but at least we arent stackoverflow
 

EvanSki

King of Raccoons
I was asking in my posts were for the local variables and how they work logically.
from the code shown really I dont think it matters if they are normal variables or local
local are for that event/script only where normal variables are for that object/script only and global.variables are available everywhere

so the use of local vars there are probably just to keep the keyboard_check_pressed values from making the hsp condition from being really long
 

Amon

Member
@DayCamp

There are better ways to deal with situations that you deem as an attack upon yourself. Posting like you did is not the way. I'm not having a go at you because I understand why you became annoyed. I just wanted you to understand why you became annoyed. You had to say yes in your mind first in order to become annoyed at what you read in posts in this thread. There is a magic button in your mind known as the 'ignore it and don't get bothered by it' button. Press it next time and enjoy your day. Enjoy your coding. Enjoy your time here. This is what the majority want.

Don't let the words of others overpower your state of calmness. There are people out there that pick up on this kind of psychological tactic and deliberately try to wind people up with it. Don't fall for it. Just say no to allowing the words to bother you.
 

DayCamp

Member
@DayCamp

There are better ways to deal with situations that you deem as an attack upon yourself. Posting like you did is not the way. I'm not having a go at you because I understand why you became annoyed. I just wanted you to understand why you became annoyed. You had to say yes in your mind first in order to become annoyed at what you read in posts in this thread. There is a magic button in your mind known as the 'ignore it and don't get bothered by it' button. Press it next time and enjoy your day. Enjoy your coding. Enjoy your time here. This is what the majority want.

Don't let the words of others overpower your state of calmness. There are people out there that pick up on this kind of psychological tactic and deliberately try to wind them up. Don't fall for it. Just say no to allowing the words to bother you.
You're right, Amon. Completely, unequivocally right (to me anyways). I should assume that Frosty is a good person who is only trying to help, regardless of their dichotomy or choice of words. Sorry Frosty, I'm too sensitive for my own good sometimes. I will remind myself of what you said Amon when engaging on community posts. Even in cases where someone is actually being a jerk, I should take the higher road, rather than getting mad and spammng rage comments. Frosty and EvanSki, I appreciate the time you took to respond to my post. And thank you Amom for your insight.
 

Amon

Member
You're right, Amon. Completely, unequivocally right (to me anyways). I should assume that Frosty is a good person who is only trying to help, regardless of their dichotomy or choice of words. Sorry Frosty, I'm too sensitive for my own good sometimes. I will remind myself of what you said Amon when engaging on community posts. Even in cases where someone is actually being a jerk, I should take the higher road, rather than getting mad and spammng rage comments. Frosty and EvanSki, I appreciate the time you took to respond to my post. And thank you Amom for your insight.
Now that..... is the best way to deal with it. Well done.
 
Top