5 Useful Scripts for GameMaker Studio 2 (and 1!)

Поділитися
Вставка
  • Опубліковано 4 жов 2024

КОМЕНТАРІ • 136

  • @SaraSpalding
    @SaraSpalding  4 роки тому +43

    !!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

    • @andreseungyeobsong4899
      @andreseungyeobsong4899 3 роки тому

      Thanks for the update!

    • @dopamine7344
      @dopamine7344 3 роки тому +2

      so what do we need to do to fix it D: very new to gamemaker lol

    • @SaraSpalding
      @SaraSpalding  3 роки тому +9

      @@dopamine7344 Use the same code but wrap them in a function definition, for example:
      function Approach() {
      (code goes here)
      }

    • @dopamine7344
      @dopamine7344 3 роки тому +4

      @@SaraSpalding oh thank you! I 100% overthought it and figured you had to do a lot more, thanks dude c:

    • @apollolane8879
      @apollolane8879 3 роки тому

      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

  • @kolegaramic260
    @kolegaramic260 7 років тому +94

    Make this a series, you can make shaders top 5 like this

    • @Jorvanius
      @Jorvanius 5 років тому +3

      Oh, man, that's the one.

    • @adamprokop
      @adamprokop 5 років тому

      ​@@Jorvanius I agree!!

  • @kahztein1397
    @kahztein1397 7 років тому +29

    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)

    • @Silenoid
      @Silenoid 7 років тому +1

      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

  • @SyntekkTeam
    @SyntekkTeam 7 років тому +17

    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 :)

  • @DragoniteSpam
    @DragoniteSpam 7 років тому +11

    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

  • @St3fa9s
    @St3fa9s 6 місяців тому

    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 :)

  • @Tezla_Insanity
    @Tezla_Insanity 7 років тому +23

    Odd moment when your watching a tutorial for Gamemaker and a Unity advertisement appears.

  • @anintendofankindaguy1368
    @anintendofankindaguy1368 7 років тому +30

    Scripts, they save sanity.

  • @zedkhov
    @zedkhov 7 років тому +1

    Thanks for posting these Shaun. Already making use of a couple of them in a prototype. Saved me a decent amount of time :)

  • @GoldScale57
    @GoldScale57 7 років тому +2

    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.

  • @didjargo
    @didjargo 6 років тому +1

    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.

  • @DJaycerOfficial
    @DJaycerOfficial 2 місяці тому

    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.

  • @anonymous1808
    @anonymous1808 4 роки тому +11

    Oh? You're Approach()ing me?

    • @St3fa9s
      @St3fa9s 6 місяців тому

      If (you're approach()ing)
      run(away);
      }

  • @MarioVelezBThinkin
    @MarioVelezBThinkin 7 років тому +1

    That wrap one helps a lot.

  • @sparkyspartan5112
    @sparkyspartan5112 7 років тому

    oh my, I needed the wrap() script badly for the longest time! Super useful video

  • @benedictnothing
    @benedictnothing 7 років тому

    Cheers for these tutorials, matey. You're a proper legend.

  • @IceMetalPunk
    @IceMetalPunk 5 років тому +6

    The Wrap script could also be turned into two lines...
    while (argument0 < argument1) { argument0 += argument2; }
    return argument0 % argument2;

  • @sabriath
    @sabriath 4 роки тому +3

    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

  • @amazingsparckman
    @amazingsparckman 7 років тому +2

    whoa cool scripts le Shaun! I am be tryin' this later on.

  • @DiamondWolfX
    @DiamondWolfX 7 років тому +1

    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.

  • @DINGOS30
    @DINGOS30 6 років тому

    wow this was a great code reference video I'm keeping this one thnx Shaun!😉

  • @zacharykowalczyk9674
    @zacharykowalczyk9674 5 років тому

    Absolutely want more videos like this! Love the Approach script.

  • @NickoTyn
    @NickoTyn 7 років тому +4

    But I like your voice on the internet.
    Keep up the good work.

  • @mushroomdude123
    @mushroomdude123 7 років тому

    I've been struggling to make a bird enemy in my game, that wave script is perfect for that!

  • @myleskerwin2
    @myleskerwin2 5 років тому

    The wrap joke was the best!

  • @illdie314
    @illdie314 7 років тому +4

    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;

  • @WangleLine
    @WangleLine 5 років тому

    These are super useful, thanks!

  • @guycomments
    @guycomments 7 років тому +1

    you should make more videos featuring more small quality of life type scripts like these

  • @slaz8761
    @slaz8761 7 років тому +2

    Very helpful videos, just like the others XD

  • @Rocky-ir1bc
    @Rocky-ir1bc 4 роки тому

    the wave script is just... perfect...

  • @jinwookim9128
    @jinwookim9128 4 роки тому

    You are god of GMS2 Thank you for your video.

  • @ShmargleFoil
    @ShmargleFoil 7 років тому +4

    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;

    • @igorthelight
      @igorthelight 6 років тому +2

      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;

  • @gms2378
    @gms2378 7 років тому

    I must be sincere, before GMS2 I wasn't following you... but those videos are great so, good job Shaun!

  • @LuigiXHero
    @LuigiXHero 7 років тому

    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.

  • @funkyb6598
    @funkyb6598 7 років тому

    Thanks for the tutorial!

  • @IceMetalPunk
    @IceMetalPunk 5 років тому

    The approach script could be made much, much shorter: return argument0 + sign(argument1 - argument0) * min(argument2, abs(argument1 - argument0))

  • @TJCorporation
    @TJCorporation 7 років тому +22

    Can you post a link to copy and paste these scripts?

    • @Aresous
      @Aresous 7 років тому

      yeah fr, very tedious having to type the whole thing.

    • @Aresous
      @Aresous 7 років тому

      thanks mate

    • @Silenoid
      @Silenoid 7 років тому

      Thanks a lot. Very helpful, as always ^^

    • @Axolotine
      @Axolotine 7 років тому +5

      puu.sh/wWGNv/835d4d702a.zip (a zip file with all the code in the vid cleaned up and with more documentation)

    • @Aresous
      @Aresous 7 років тому

      axolotine, appreciate the effort homie.

  • @joshuacahill2139
    @joshuacahill2139 7 років тому

    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

  • @VICE-H3RO
    @VICE-H3RO 4 роки тому

    Lot of useful scripts :)

  • @Eddygeek18
    @Eddygeek18 5 років тому

    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

    • @lionjeff1640
      @lionjeff1640 2 роки тому

      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!

  • @zheckman89
    @zheckman89 5 років тому

    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;

  • @kanolem
    @kanolem Рік тому

    hello, if it's possible. Can you make an updated version for this useful scripts.

  • @AgentAvis
    @AgentAvis 7 років тому

    Cool i'm getting gamedev adds on gamedev videos.

  • @victorstk
    @victorstk 6 років тому

    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."

  • @BluecoreG
    @BluecoreG 7 років тому +3

    Wouldn't it be better to use
    if (70 > irandom (100))

    • @einsfuffzich
      @einsfuffzich 7 років тому +1

      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%.

    • @BluecoreG
      @BluecoreG 7 років тому +1

      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"

    • @HM1xx
      @HM1xx 7 років тому

      if (100 > irandom(100)) // false with 1/101 chance

    • @tonystroemsnaes554
      @tonystroemsnaes554 6 років тому

      umm

  • @deldarel
    @deldarel 7 років тому

    It says Wave() when you explain Approach()

  • @spiralcraft8957
    @spiralcraft8957 6 років тому

    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.

  • @Diegovz01
    @Diegovz01 Рік тому

    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?

  • @clubpenguinsenpai6482
    @clubpenguinsenpai6482 6 років тому

    at the beginning of approach it says wave

  • @rinrin4711
    @rinrin4711 6 років тому

    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;

  • @H0gwashing
    @H0gwashing 5 років тому +1

    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

    • @williamwolfe962
      @williamwolfe962 2 роки тому

      wrongo, its testing if .7 is greater than the random number, so .1-.6 return true, .7-.9 return false.

    • @H0gwashing
      @H0gwashing 2 роки тому

      @@williamwolfe962 i am a dipshit, thank you

  • @foof7352
    @foof7352 5 років тому

    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.

  • @odaghast
    @odaghast 6 років тому

    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;

    • @Karak-_-
      @Karak-_- 4 роки тому

      Thou shall name your variables descriptively.

  • @AlexFerran
    @AlexFerran 7 років тому

    What's the difference between Wrap and just val = (val mod max-min) + min?

  • @mahmoud.zayedd
    @mahmoud.zayedd 7 років тому

    real time in game maker please . :)

  • @CaptainMangles
    @CaptainMangles 7 років тому

    I think you named the first script wrong in this video.

  • @SuperBucketbot
    @SuperBucketbot 7 років тому +1

    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?

    • @SuperBucketbot
      @SuperBucketbot 7 років тому

      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. :)

    • @icouch5781
      @icouch5781 6 років тому +2

      Sorry to bother, but what was the solution? I guess Shaun deleted his reply.

    • @victorstk
      @victorstk 6 років тому

      i want to see the solution also please

    • @peppermintgal4302
      @peppermintgal4302 5 років тому

      @@icouch5781 Probably something like having a timing variable to base the wave on, rather than using the time the game has been running for?

  • @SonictheHedgehogInRealLife
    @SonictheHedgehogInRealLife 2 роки тому

    Does anyone know how to do the approach script in C#?

  • @raydin9485
    @raydin9485 6 років тому

    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?

    • @icouch5781
      @icouch5781 6 років тому

      Yeah, they're basically just global functions.

  • @chasecollins5349
    @chasecollins5349 6 років тому

    fucking superb you funky little cowboy

  • @BloonyFox
    @BloonyFox 4 роки тому

    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

  • @UltimoGames
    @UltimoGames 7 років тому

    I find it weird that GameMaker 8.1 isn't available for free download on the YoYoGames website..

    • @leochima6042
      @leochima6042 7 років тому

      im pretty sure that version doesnt exist...

    • @DiamondWolfX
      @DiamondWolfX 6 років тому

      It does. Ever since Studio they stopped supporting it though.

  • @cristobalvarela93
    @cristobalvarela93 5 років тому

    someone knows if there is a videos of the GameMaker Studio 2 in spanish (using drag and drop)

  • @Juanlups4BlogspotEs
    @Juanlups4BlogspotEs 5 років тому

    Scrip warp need speed or something? It dont works

  • @Watermelonsa
    @Watermelonsa 7 років тому

    Thx

  • @zarkha_
    @zarkha_ 6 років тому

    My Wave() don’t work on game maker studio 1...
    :(

  • @Elf0Adrianus
    @Elf0Adrianus 7 років тому

    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.

  • @jakob6455
    @jakob6455 7 років тому

    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.

    • @leochima6042
      @leochima6042 7 років тому

      you can change the "interpolate colours between pictures" thing in global game settings and the effect wont appear, i think

  • @KirmesMan
    @KirmesMan 7 років тому +1

    Fress!

  • @The_hangman1
    @The_hangman1 7 років тому

    What i learn here can i use on unreal?

  • @truebitoy1597
    @truebitoy1597 7 років тому

    There's lerp in GMS so there's no need for the Approach script

    • @DiamondWolfX
      @DiamondWolfX 6 років тому

      Lerp is for relative values (50% between the numbers) where Approach is for absolute values (50 above the number).

  • @davidlecompte9467
    @davidlecompte9467 5 років тому

    what the difference with doing a script and doing a variable with the script ? is it just 2 option i have ?

    • @TheFatHampster
      @TheFatHampster 5 років тому

      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.

  • @cameronsanders4169
    @cameronsanders4169 7 років тому +1

    What language do you use in game maker?

    • @JoelLikesPigs
      @JoelLikesPigs 7 років тому

      GML it's its own language

    • @massim0g
      @massim0g 7 років тому

      Yeah, it's based on C.

    • @Sagitta62
      @Sagitta62 6 років тому

      shout out for C/C++ aka Cpp once you know the basic GML is a breeze

  • @kugelogaming6510
    @kugelogaming6510 7 років тому

    is there a command to check if a variable is not set?

    • @DiamondWolfX
      @DiamondWolfX 6 років тому

      There is variable_local/global_exists, but GMS1 skipped that...
      At least they brought it back in GMS2

    • @Karak-_-
      @Karak-_- 4 роки тому

      Variable_instance_exists(id,"variable")
      Id is id of instance and "variable" is string with name of variable.

  • @Goatnime
    @Goatnime 7 років тому +2

    I wish i had my PC so i could use this ;-;

    • @shogunero3.6
      @shogunero3.6 7 років тому +2

      Herofang don't you have any kind of computer???

    • @Goatnime
      @Goatnime 7 років тому

      アルジュン Yumeito I had one but my computer messed up really bad beyond repair :(

  • @BriBrando
    @BriBrando 7 років тому +1

    Hey can yah make a super fnaf tutorial on game maker 1

    • @RoyFlaherty
      @RoyFlaherty 7 років тому +3

      I doubt he'd do something super specific. Maybe just learn the GameMaker Language to code it yourself

    • @greatduck5297
      @greatduck5297 7 років тому

      a fnaf tutorial wouldn't make sense. More likely, he'd do an AI tutorial on arbitrary directed graph maps.

  • @Axolotine
    @Axolotine 7 років тому +5

    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

    • @alexaquila6648
      @alexaquila6648 6 років тому

      Kinda late to this video but thanks for the efforts, you haven't been ignored

    • @DecayingEkzykesFan
      @DecayingEkzykesFan 3 роки тому +1

      The link is dead...
      I shall die with it

  • @TheRexion
    @TheRexion 7 років тому +5

    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.

  • @loconnor1065
    @loconnor1065 7 років тому

    Why go to the effort to make something so shit for a product no one cares about