!!SCRIPTS HAVE CHANGED IN VERSION 2.3!! Rather than being custom functions, scripts now simply contain functions (and can contain multiple!) so they must now be declared by using the "function" statement This will be obvious upon making a new script, the declaration code you need will be created for you. Instead of calling the script itself, you now call the functions within them! Here's an explanation from YoYo: help.yoyogames.com/hc/en-us/articles/360005277377
i know Im asking the wrong place but does anyone know a trick to get back into an instagram account?? I somehow forgot the account password. I love any tricks you can give me
One thing I always found to be really useful is having a script that simply returns a certain amount of seconds. So just: return ceil(argument0*room_speed); And then writing s(1) for one second, s(0.5) for half a second etc. I just find it to be a lot more intuitive to write most of my time based code and whatnot as seconds instead of ticks. You can even use it for setting movement speed per second or slowing down/speeding up time (by using a global variable instead of room_speed). The ceil part is just a personal preference so I know I've got a whole number (and it's not zero)
That's cool and I never thought to make it as a script. Thanks a lot man. Just to add more info about, it's important to not mistake the definition of time itself with the one dependent on the frame progression. Since the framerate is unstable, the higher the value in seconds you put in the script, the worst is the error obtained in time lag. I understood that when I dealt with a rhythm game and I needed a perfect sync. In those case, It's best to work directly with real time timers
I usually make a print function. it works just like show_debug_message except it's easier to type and you can write things like print("x: ",5) without having to do any casting :)
A few "library" scripts that I use in pretty much every project - - a bunch of *array* functions that GMS1 didn't have - *instanceof* : returns whether an instance is descended from (or is, itself) an object type - *is_clamed* : Sort of an inverse to _clamp()_ - *null* : Takes any arbitrary number of arguments, does nothing, returns zero. Used often in tandem with _script_execute()_ - *print* : Saves typing from _show_debug_message()_ - *scaleTo* : scales a value from one maximum to another
Great tutorial! I used to reuse my chunks of code very often by copying and pasting them, which made my code very hard to read, thanks for explaining this, I'll definitely use scripts in the future :)
This is a script I use a lot. Mostly for Jumping and Dashing. I think it's kinda simple math but it helps if you forget even simple formulas a lot like I do. ///Set_Dist_Vel(deceleration, distance); var decel = abs( argument0 ); var dist = argument1; return sign( dist ) * ( sqrt( decel * 2 * abs( dist ) ) ); //or just use return sqrt( decel * 2 * abs( dist ) ) //I tend to be overly cautious with my math Example: jump_speed = Set_Dist_Vel(gravity_value, -16*3) This helps makes sure that the character jumps the same height (-48 pixels) no matter what their "gravity_value" is.
The most helpful thing I learned in this video was the whole @discription and @param thing for the custom scripts. Beforehand, I would frequently need to open up the window for my script when I want to use it because I cannot remember what arguments do what. Now I don't have to, thanks for that.
I personally created a function called loop_menu() which kinda works like clamp but instead of stopping the value at the max, it’ll go back to the beginning when attempting to go down again in the menu. I also used it in my battle system for making sure the turn variable never goes over the length of units variable.
Wrap: if(_val < _min) return _max-(_min-_val)%(_max-_min); else return _min+(_val-_min)%(_max-_min); Not entirely sure why you were +1 everywhere in the script, but whatever, the above script uses no loops and solves in one go
I recently made a simple script called xyg. It sets the hspeed, vspeed, and gravity (or any related variables you use). I use it in things like fireballs, but it can be used for quite a few things.
A script for movement that is the same independent of framerate (I didn't come up with a name whatever): scr( val, fps) var dt = delta_time/1000000; return argument0*argument1*dt;
Here's a much simpler wrap script I came up with a while ago. ///wrap(val, min, max) var val = argument0; var minimum = argument1; var maximum = argument2; var range = maximum - minimum; while(val >= maximum) val -= range; while(val < minimum) val += range; return val;
Here is my version of this script. It must be a little bit faster: /// @desription Wrap)value, minimum, maximum) /// @param value /// @param minimum /// @param maximum var range = argument2 - argument1; while(argument0 >= argument2) argument0 -= range; while(argument0 < argument1) argument0 += range; return argument0;
Loved wave and the idea for wrap. But I have a few questions. 1. Why does wrap look so complicated? While loops? Here is what I got, I use mod just in case the value was adjusted that much: [serious edit - I revisited wrap, last was cleaner but this is even more so] var curv = argument[0], minv = argument[1], maxv = argument[2]; var delta = maxv - minv; var result = (curv - minv) % delta; if result
they seem useful in certain scenarios, but i wouldnt use them enough to waste time at the start of each project typing them all in. plus with all of them i didn't feel they saved that much extra time than just writing the code in
You can copy assets from one project to another. Now with the 2.3 functions, I think you can store all useful ones into a single script and import in a new project? Just FYI, hope it helps!
I don't really know why that Wrap function is as complicated as it is, but if you tried copying it and it's annoying you try this one out instead. It will have a small problem where if your value is less than min - (max-min), but as long as you're not using the function with steps larger than (max-min) you should be OK. Or just feel free to fix that corner case, would probably be easier than the wrap in the video. /// @description wrap(value, min, max) /// @param value /// @param min /// @param max var _val = argument0; var _min = argument1; var _max = argument2; if( _val > _max ) _val = _min + (_val % _max); else if( _val < _min ) _val = _max - (_min - _val); return _val;
Having the same issue as Matt Kemp with the Wave Script "Having an issue with the Wave script. Any object I code to move via the script ( y = wave(y+3, y-3, 2, 0 ) or any variation of that )seems to never properly reset upon room, or game restart."
Woops, meant to write. if (70 > irandom (100)) That way you actually have a 70% chance of true, and "70" may be easier for someone to read and understand than "0.7"
new to coding but i use window_set_cursor (cr_none) cursor_sprite = spr_CustomCursor ; to set the cursor invis and add a custom one. i add it in the create event of my main player not sure if that's the right place but it works.
I am not a native english speaker, so i might have got it wrong but as I understand it, the Wrap() function should make something like a loop between _min and _max so the _val always stays inside this interval. If I got it right, then this line of code should be able to replace all of the code under variable definition: "return ((_val - _min) mod (_max - _min + 1)) + min;". I really want to know if I missed something, cause this code works perfectly on paper) EDIT_1: Ok, I have just realised that in GML -2 mod 7 = -2 and not 5, and it doesn't work with real numbers... I'm a bit disappointed in GML now:c EDIT_2: This code below works perfectly for Integer values: /// @description Wrap(value, min, max) /// @function Wrap /// @param value /// @param min /// @param max var _val1= argument0 - argument1; var _val2 = argument2- argument1; return ((_val1 % (_val2+1)) + (_val2 & -(_val1 < 0))) + argument1;
The scripts are really nice to organize and make code more readable, but is there any efficiency downside to using this a lot? In terms of replacing code with scripts for things that aren't going to be universally used.
My own wrap. idk if its better, worse or doesnt work... var a = argument[0]; var b = argument[1]; var c = argument[2]; var r = (a-b+c) mod c; return r+b;
Having an issue with the Wave script. Any object I code to move via the script ( y = wave(y+3, y-3, 2, 0 ) or any variation of that )seems to never properly reset upon room, or game restart. This results in enemies/bosses having differing positions than I'd like. For example a boss I've made will sometimes fly up and down normally, sometimes much lower, spending 50% of its time in the floor, or vice versa with the ceiling The movement is constant, and perfectly balanced. The only issue is where the movement begins I think. Any advice?
Thank you very much Shaun. I assumed everything would reset upon room/game restart. When it wasn't, I thought I should mess with the Create Event or something, but to no effect. This has solved my issue completely though, I appreciate it a lot. Keep making quality content my friend. :)
I'm new to coding and still learning python. Once I downloaded gamemaker, I understood some of the things but most of it didn't make sense to me. So are scripts basically like functions where there are pre-defined functions and functions that you can make?
chance script is most easy to use in this mode /// @description Chance(percent) /// @param percent // Returns true or false depending on RNG // ex: // Chance(70); -> Returns true 70% of the time // I change 0.7 to 70 to more like a real percentage return argument0 > random(100); // I change 1 to 100, to do more easy select a percentage
Wow, those scripts look like very useful! :) If all are free for commercial use? Maybe it's obvious question but I'm start use GMS2 newly and I newbie in this things.
well if you do var ScriptOutput = scriptName(); and your script returns for instance "potato" then ScriptOutput will be "potato". Make sense? just a way of storing the returned value of the script.
!!SCRIPTS HAVE CHANGED IN VERSION 2.3!!
Rather than being custom functions, scripts now simply contain functions (and can contain multiple!) so they must now be declared by using the "function" statement
This will be obvious upon making a new script, the declaration code you need will be created for you. Instead of calling the script itself, you now call the functions within them!
Here's an explanation from YoYo: help.yoyogames.com/hc/en-us/articles/360005277377
Thanks for the update!
so what do we need to do to fix it D: very new to gamemaker lol
@@dopamine7344 Use the same code but wrap them in a function definition, for example:
function Approach() {
(code goes here)
}
@@SaraSpalding oh thank you! I 100% overthought it and figured you had to do a lot more, thanks dude c:
i know Im asking the wrong place but does anyone know a trick to get back into an instagram account??
I somehow forgot the account password. I love any tricks you can give me
Make this a series, you can make shaders top 5 like this
Oh, man, that's the one.
@@Jorvanius I agree!!
One thing I always found to be really useful is having a script that simply returns a certain amount of seconds.
So just:
return ceil(argument0*room_speed);
And then writing s(1) for one second, s(0.5) for half a second etc.
I just find it to be a lot more intuitive to write most of my time based code and whatnot as seconds instead of ticks. You can even use it for setting movement speed per second or slowing down/speeding up time (by using a global variable instead of room_speed).
The ceil part is just a personal preference so I know I've got a whole number (and it's not zero)
That's cool and I never thought to make it as a script. Thanks a lot man.
Just to add more info about, it's important to not mistake the definition of time itself with the one dependent on the frame progression. Since the framerate is unstable, the higher the value in seconds you put in the script, the worst is the error obtained in time lag.
I understood that when I dealt with a rhythm game and I needed a perfect sync. In those case, It's best to work directly with real time timers
I usually make a print function. it works just like show_debug_message except it's easier to type and you can write things like print("x: ",5) without having to do any casting :)
A few "library" scripts that I use in pretty much every project -
- a bunch of *array* functions that GMS1 didn't have
- *instanceof* : returns whether an instance is descended from (or is, itself) an object type
- *is_clamed* : Sort of an inverse to _clamp()_
- *null* : Takes any arbitrary number of arguments, does nothing, returns zero. Used often in tandem with _script_execute()_
- *print* : Saves typing from _show_debug_message()_
- *scaleTo* : scales a value from one maximum to another
Great tutorial! I used to reuse my chunks of code very often by copying and pasting them, which made my code very hard to read, thanks for explaining this, I'll definitely use scripts in the future :)
Odd moment when your watching a tutorial for Gamemaker and a Unity advertisement appears.
Scripts, they save sanity.
Thanks for posting these Shaun. Already making use of a couple of them in a prototype. Saved me a decent amount of time :)
This is a script I use a lot. Mostly for Jumping and Dashing. I think it's kinda simple math but it helps if you forget even simple formulas a lot like I do.
///Set_Dist_Vel(deceleration, distance);
var decel = abs( argument0 );
var dist = argument1;
return sign( dist ) * ( sqrt( decel * 2 * abs( dist ) ) );
//or just use return sqrt( decel * 2 * abs( dist ) )
//I tend to be overly cautious with my math
Example:
jump_speed = Set_Dist_Vel(gravity_value, -16*3)
This helps makes sure that the character jumps the same height (-48 pixels) no matter what their "gravity_value" is.
The most helpful thing I learned in this video was the whole @discription and @param thing for the custom scripts. Beforehand, I would frequently need to open up the window for my script when I want to use it because I cannot remember what arguments do what. Now I don't have to, thanks for that.
I personally created a function called loop_menu() which kinda works like clamp but instead of stopping the value at the max, it’ll go back to the beginning when attempting to go down again in the menu. I also used it in my battle system for making sure the turn variable never goes over the length of units variable.
Oh? You're Approach()ing me?
If (you're approach()ing)
run(away);
}
That wrap one helps a lot.
oh my, I needed the wrap() script badly for the longest time! Super useful video
Cheers for these tutorials, matey. You're a proper legend.
The Wrap script could also be turned into two lines...
while (argument0 < argument1) { argument0 += argument2; }
return argument0 % argument2;
Wrap:
if(_val < _min)
return _max-(_min-_val)%(_max-_min);
else
return _min+(_val-_min)%(_max-_min);
Not entirely sure why you were +1 everywhere in the script, but whatever, the above script uses no loops and solves in one go
whoa cool scripts le Shaun! I am be tryin' this later on.
I recently made a simple script called xyg. It sets the hspeed, vspeed, and gravity (or any related variables you use). I use it in things like fireballs, but it can be used for quite a few things.
wow this was a great code reference video I'm keeping this one thnx Shaun!😉
Absolutely want more videos like this! Love the Approach script.
But I like your voice on the internet.
Keep up the good work.
I've been struggling to make a bird enemy in my game, that wave script is perfect for that!
The wrap joke was the best!
A script for movement that is the same independent of framerate (I didn't come up with a name whatever):
scr( val, fps)
var dt = delta_time/1000000;
return argument0*argument1*dt;
These are super useful, thanks!
you should make more videos featuring more small quality of life type scripts like these
Very helpful videos, just like the others XD
the wave script is just... perfect...
You are god of GMS2 Thank you for your video.
Here's a much simpler wrap script I came up with a while ago.
///wrap(val, min, max)
var val = argument0;
var minimum = argument1;
var maximum = argument2;
var range = maximum - minimum;
while(val >= maximum) val -= range;
while(val < minimum) val += range;
return val;
Here is my version of this script. It must be a little bit faster:
/// @desription Wrap)value, minimum, maximum)
/// @param value
/// @param minimum
/// @param maximum
var range = argument2 - argument1;
while(argument0 >= argument2)
argument0 -= range;
while(argument0 < argument1)
argument0 += range;
return argument0;
I must be sincere, before GMS2 I wasn't following you... but those videos are great so, good job Shaun!
oh I programmed my own warp script before but it was a lot more bare bones and it worked but this warp seems a lot better.
Thanks for the tutorial!
The approach script could be made much, much shorter: return argument0 + sign(argument1 - argument0) * min(argument2, abs(argument1 - argument0))
Can you post a link to copy and paste these scripts?
yeah fr, very tedious having to type the whole thing.
thanks mate
Thanks a lot. Very helpful, as always ^^
puu.sh/wWGNv/835d4d702a.zip (a zip file with all the code in the vid cleaned up and with more documentation)
axolotine, appreciate the effort homie.
Loved wave and the idea for wrap. But I have a few questions.
1. Why does wrap look so complicated? While loops? Here is what I got, I use mod just in case the value was adjusted that much:
[serious edit - I revisited wrap, last was cleaner but this is even more so]
var curv = argument[0], minv = argument[1], maxv = argument[2];
var delta = maxv - minv;
var result = (curv - minv) % delta;
if result
Lot of useful scripts :)
they seem useful in certain scenarios, but i wouldnt use them enough to waste time at the start of each project typing them all in. plus with all of them i didn't feel they saved that much extra time than just writing the code in
You can copy assets from one project to another. Now with the 2.3 functions, I think you can store all useful ones into a single script and import in a new project? Just FYI, hope it helps!
I don't really know why that Wrap function is as complicated as it is, but if you tried copying it and it's annoying you try this one out instead. It will have a small problem where if your value is less than min - (max-min), but as long as you're not using the function with steps larger than (max-min) you should be OK. Or just feel free to fix that corner case, would probably be easier than the wrap in the video.
/// @description wrap(value, min, max)
/// @param value
/// @param min
/// @param max
var _val = argument0;
var _min = argument1;
var _max = argument2;
if( _val > _max )
_val = _min + (_val % _max);
else if( _val < _min )
_val = _max - (_min - _val);
return _val;
hello, if it's possible. Can you make an updated version for this useful scripts.
Cool i'm getting gamedev adds on gamedev videos.
Having the same issue as Matt Kemp with the Wave Script
"Having an issue with the Wave script. Any object I code to move via the script ( y = wave(y+3, y-3, 2, 0 ) or any variation of that )seems to never properly reset upon room, or game restart."
Wouldn't it be better to use
if (70 > irandom (100))
Since irandom always returns an integer, irandom(1) will return 0 or 1, with 50% chance each. So the chance of that if statement would always be 50%.
Woops, meant to write.
if (70 > irandom (100))
That way you actually have a 70% chance of true, and "70" may be easier for someone to read and understand than "0.7"
if (100 > irandom(100)) // false with 1/101 chance
umm
It says Wave() when you explain Approach()
new to coding but i use
window_set_cursor (cr_none)
cursor_sprite = spr_CustomCursor ;
to set the cursor invis and add a custom one. i add it in the create event of my main player not sure if that's the right place but it works.
I'm checking the wave function because I'm making some moving platforms but I'm struggling to figure out what does the offset argument does?
at the beginning of approach it says wave
I am not a native english speaker, so i might have got it wrong but as I understand it, the Wrap() function should make something like a loop between _min and _max so the _val always stays inside this interval. If I got it right, then this line of code should be able to replace all of the code under variable definition: "return ((_val - _min) mod (_max - _min + 1)) + min;".
I really want to know if I missed something, cause this code works perfectly on paper)
EDIT_1:
Ok, I have just realised that in GML -2 mod 7 = -2 and not 5, and it doesn't work with real numbers...
I'm a bit disappointed in GML now:c
EDIT_2:
This code below works perfectly for Integer values:
/// @description Wrap(value, min, max)
/// @function Wrap
/// @param value
/// @param min
/// @param max
var _val1= argument0 - argument1;
var _val2 = argument2- argument1;
return ((_val1 % (_val2+1)) + (_val2 & -(_val1 < 0))) + argument1;
6:57 actually, if it's testing it to be more than 0.7, then that means it only has a 30% chance of happening
wrongo, its testing if .7 is greater than the random number, so .1-.6 return true, .7-.9 return false.
@@williamwolfe962 i am a dipshit, thank you
The scripts are really nice to organize and make code more readable, but is there any efficiency downside to using this a lot? In terms of replacing code with scripts for things that aren't going to be universally used.
My own wrap. idk if its better, worse or doesnt work...
var a = argument[0]; var b = argument[1]; var c = argument[2];
var r = (a-b+c) mod c;
return r+b;
Thou shall name your variables descriptively.
What's the difference between Wrap and just val = (val mod max-min) + min?
real time in game maker please . :)
I think you named the first script wrong in this video.
Having an issue with the Wave script.
Any object I code to move via the script ( y = wave(y+3, y-3, 2, 0 ) or any variation of that )seems to never properly reset upon room, or game restart.
This results in enemies/bosses having differing positions than I'd like.
For example a boss I've made will sometimes fly up and down normally, sometimes much lower, spending 50% of its time in the floor, or vice versa with the ceiling
The movement is constant, and perfectly balanced. The only issue is where the movement begins I think.
Any advice?
Thank you very much Shaun. I assumed everything would reset upon room/game restart. When it wasn't, I thought I should mess with the Create Event or something, but to no effect. This has solved my issue completely though, I appreciate it a lot.
Keep making quality content my friend. :)
Sorry to bother, but what was the solution? I guess Shaun deleted his reply.
i want to see the solution also please
@@icouch5781 Probably something like having a timing variable to base the wave on, rather than using the time the game has been running for?
Does anyone know how to do the approach script in C#?
I'm new to coding and still learning python. Once I downloaded gamemaker, I understood some of the things but most of it didn't make sense to me. So are scripts basically like functions where there are pre-defined functions and functions that you can make?
Yeah, they're basically just global functions.
fucking superb you funky little cowboy
chance script is most easy to use in this mode
/// @description Chance(percent)
/// @param percent
// Returns true or false depending on RNG
// ex:
// Chance(70); -> Returns true 70% of the time
// I change 0.7 to 70 to more like a real percentage
return argument0 > random(100); // I change 1 to 100, to do more easy select a percentage
I find it weird that GameMaker 8.1 isn't available for free download on the YoYoGames website..
im pretty sure that version doesnt exist...
It does. Ever since Studio they stopped supporting it though.
someone knows if there is a videos of the GameMaker Studio 2 in spanish (using drag and drop)
Scrip warp need speed or something? It dont works
Thx
for what?!? dont spam.
My Wave() don’t work on game maker studio 1...
:(
mine does
Wow, those scripts look like very useful! :)
If all are free for commercial use?
Maybe it's obvious question but I'm start use GMS2 newly and I newbie in this things.
Could anyone tell me what is the best way to resize sprites? I want to make them bigger, but the strange effect appears. I need the solution.
you can change the "interpolate colours between pictures" thing in global game settings and the effect wont appear, i think
Fress!
What i learn here can i use on unreal?
There's lerp in GMS so there's no need for the Approach script
Lerp is for relative values (50% between the numbers) where Approach is for absolute values (50 above the number).
what the difference with doing a script and doing a variable with the script ? is it just 2 option i have ?
well if you do
var ScriptOutput = scriptName();
and your script returns for instance "potato" then ScriptOutput will be "potato". Make sense? just a way of storing the returned value of the script.
What language do you use in game maker?
GML it's its own language
Yeah, it's based on C.
shout out for C/C++ aka Cpp once you know the basic GML is a breeze
is there a command to check if a variable is not set?
There is variable_local/global_exists, but GMS1 skipped that...
At least they brought it back in GMS2
Variable_instance_exists(id,"variable")
Id is id of instance and "variable" is string with name of variable.
I wish i had my PC so i could use this ;-;
Herofang don't you have any kind of computer???
アルジュン Yumeito I had one but my computer messed up really bad beyond repair :(
Hey can yah make a super fnaf tutorial on game maker 1
I doubt he'd do something super specific. Maybe just learn the GameMaker Language to code it yourself
a fnaf tutorial wouldn't make sense. More likely, he'd do an AI tutorial on arbitrary directed graph maps.
For my fellow script kiddies, here's all the code in this video (slightly cleaned up and with more documentation):
puu.sh/wWGNv/835d4d702a.zip
Kinda late to this video but thanks for the efforts, you haven't been ignored
The link is dead...
I shall die with it
I think you might be too close to your microphone. I can hear your lips smacking every time you talk and it is just unbearable for me.
Why go to the effort to make something so shit for a product no one cares about