GameMaker Studio 2.3: *OOP* GML with Structs & Constructors

  Рет қаралды 21,486

GameMakerStation - Matharoo

GameMakerStation - Matharoo

Күн бұрын

Пікірлер: 84
@GameMakerStation
@GameMakerStation 4 жыл бұрын
What do you think of the new GML? Let me know your thoughts, and if you have any questions, our community on Discord can help! (You can easily find me there too) - discord.gg/TykHyqK
@druncle1977
@druncle1977 4 жыл бұрын
I don't like the "new" function you use to create light weight objects. In the past, I had my own "new" function to create objects, instead of having to type instance_create(x,y,l,name). I can no longer do that :( I'd much prefer to use light weight objects tbh, but since you can't do a actions to all light weight objects without looping through them, they pretty much become useless. With regular objects, you can just say: with(instanceName){do action} which is much much more efficient than looping through each object.
@RaonakDM
@RaonakDM 4 жыл бұрын
proper object oriented programming in GML is a gamechanger.
@chooby4405
@chooby4405 4 жыл бұрын
Finally i can create Vectors in gamemaker! Thats gonna be so usefull! I dont even want to work on my game anymore i just want 2.3 to come out.
@DanielWillen
@DanielWillen 4 жыл бұрын
@@javiermeza2557 The whole point of a abstractions in a programming language is to have the programmer focus on the application logic, not manipulation of values in variables. You could still make vectors in GM 1.4 using arrays and such, but it was more convoluted and ugly to read. It's easier to write, read and maintain. If I know something "is" a vec2 there's no confusion what I can do with it, all I have to do is check the definition.
@saphi20
@saphi20 4 жыл бұрын
cant wait, i’ve been waiting like a year to start my game project since i heard they where improving gml ;n;
@stubz1369
@stubz1369 4 жыл бұрын
Awesome stuff. So much to get my head around. Chained accessors next please!
@iShawtrcwbky
@iShawtrcwbky 4 жыл бұрын
This is huge for GML I feel like. Can't wait to upgrade to GMS2. Thanks for the video!
@hyeonsuha3137
@hyeonsuha3137 4 жыл бұрын
Now I got permission of GML from my computer engineering professor for gradution portfolio. The only thing left is to make something. But I'm lazy duck quack.
@babywinchester1391
@babywinchester1391 2 жыл бұрын
I enjoy your videos very much, straightforward and informative!
@AiguretDuren
@AiguretDuren 4 жыл бұрын
Hey, thank you for this video. I'm new to GMS2, and your videos are helping me a lot. You have my subscription.
@Gaming-Appscom
@Gaming-Appscom 4 жыл бұрын
Probably the best tutorial I have ever seen. Very nice Bro!
@oldbomb
@oldbomb 3 жыл бұрын
I love your voice and you are explaining very well, thanks for your videos!
@prowokator
@prowokator 4 жыл бұрын
Excellent! Gm documentation on the subject was quite confusing. Thanks!
@jk-gn2fu
@jk-gn2fu 4 жыл бұрын
This will actually make networking much easier for me. No need to save all client info as ds_map or ds_list anymore.
@GrizzliusMaximus
@GrizzliusMaximus 4 жыл бұрын
Nice Tutorial! I watched it several times to get a better understanding of how structs work. I just have a few questions. If you make a new struct inside the parameters of the function, wouldnt it stay in memory if you dont delete it? example: vec2.add(new vector2(20, 30)); . Also, are the structs pass by value or reference? Will I be essentially duplicating a struct by passing it through a function?
@GameMakerStation
@GameMakerStation 4 жыл бұрын
They're passed by reference. Structs are garbage collected when they're no longer needed. You're just passing a struct as a parameter (not storing it in a variable), so once the function is over, the struct is probably gone.
@TheInevitableHulk
@TheInevitableHulk 4 жыл бұрын
7:00 Why does it return a string when you try to convert a function into a string without specifying .toString?
@anixias
@anixias 4 жыл бұрын
GameMaker is calling that function under the hood to convert it to a string, if the function exists. Many programming languages have a built-in function called toString that you can override that is called when using the object where a string is expected.
@TheInevitableHulk
@TheInevitableHulk 4 жыл бұрын
@@anixias Thank you, I was wondering if that was the case then why wasn't it highlighted orange or something, haha.
@Lulech23
@Lulech23 4 жыл бұрын
@@TheInevitableHulk It's because the toString variable is just a reference here, it's the "return" command that's actually making a string appear. You could name the variable whatever you want.
@GameMakerStation
@GameMakerStation 4 жыл бұрын
@@Lulech23 Well, the function still has to be in the "toString" variable, otherwise it won't work.
@NoLootStudios
@NoLootStudios 4 жыл бұрын
Nice, these features will come in handy :D Nice, vid, buddy.
@petermorris1769
@petermorris1769 4 жыл бұрын
A very interesting video, thanks. I would be surprised though if you are correct about every instance of Vector3 having its own copy of Add. I expect that behind the scenes GML shares the same function and has an implicit "self". This is how other languages do it. By the way, is there a way to call base.toString() in a descendant class so just the "z" can be added? Also, could you pass an instance of a child struct to a function that expects an instance of parent struct and it will still work okay (i.e. polymorphism)?
@GameMakerStation
@GameMakerStation 4 жыл бұрын
Yes, it mostly likely does create a new function for each struct, unless you use self. I'm not aware of any way to call parent functions in child constructors. If you have access to the beta, you can ask in the beta forums. 🙂 And yes to your final question - that should work. GM doesn't have types, so it wouldn't strictly expect a struct of one type, and inside that function you would just be expecting the struct to have some particular members, which a child constructor would. So, polymorphism is possible.
@ddj3428
@ddj3428 4 жыл бұрын
I still haven't get my Beta ticket(my number is nearly 400 !), so i just can only try to code with 2.3GML by the note in GMS2, sad. But i think the changing of GML would be worth for waitng, the "OOP" is something can improve the coding a lot. (method function, and struct light object)
@NeZversSounds
@NeZversSounds 4 жыл бұрын
Wow, now GM is getting like propper programming language.
@habarvaz
@habarvaz 4 жыл бұрын
Wow, this is truly a game changer, no pun intended. Thanks for the great video. Is the GameMaker 2.3 Beta open for everyone? Do you recommend using it now, or wait for an official release?
@GameMakerStation
@GameMakerStation 4 жыл бұрын
It's not open for all, you have to apply through the link here (see bottom of the page): www.yoyogames.com/blog/565/gamemaker-studio-2-version-2-3-beta-release And yes, I recommend using it once you get your hands on it. Just make small demos and learn about the new features; only use it for production once it comes to stable.
@DanielWillen
@DanielWillen 4 жыл бұрын
Do you have a Patreon? Very instructive and to the point.
@GameMakerStation
@GameMakerStation 4 жыл бұрын
Thanks! I don't run a Patreon or a Ko-fi, because I make paid content on Udemy and running a Patreon would just be excessive. You can check out my latest course on Udemy if you're interested: www.udemy.com/course/crafting/?referralCode=81153850CB978F6D9ECC
@karlstenator
@karlstenator 4 жыл бұрын
This is so RAD! I can't wait to get my hands on 2.3! >_
@Grimsikk
@Grimsikk 2 жыл бұрын
If you or anybody else could help teach me a little more hands-on about Structs and Struct Inheritance, I would greatly appreciate it. I'm having trouble wrapping my head around it. I'm trying to make a Loot Randomizer for a TTRPG I've been making. I started making a working version that uses Arrays, irandom_range for "dice rolls", and a loooot of "if" statements to narrow down what item is being awarded, what rarity it is, what bonus effects it has, what material it's made out of, etc. etc. I recently had someone on Reddit suggest I avoid "if" statements for this and use Structs and Struct inheritance instead, but I have no idea how to even begin reworking my code for that. If you or anybody else has any idea on how I should approach reworking this with Structs and Struct inheritance, I would be eternally grateful! Here is just a snippet of my code. I have a ton of arrays in my Create event that hold all the different weapons, armor, etc., and this code below is in my Press Space event to "roll" for a randomized item. It all works as intended, but I want to learn how to clean it up for future customizability. //// LOOT TYPE ROLL //// LootType=(LootArray[irandom(array_length(LootArray)-1)]); if LootType="Weapon" { {LootRoll=(irandom_range(1,3))} if LootRoll=1 { {GearType="Melee"} {if MatType="Scrap" {ItemName=(ScrapMelee[irandom(array_length(ScrapMelee)-1)])}} {if MatType="Wood" {ItemName=(WoodMelee[irandom(array_length(WoodMelee)-1)])}} {if MatType="Stone" {ItemName=(StoneMelee[irandom(array_length(StoneMelee)-1)])}} {if MatType="RadIron" {ItemName=(RadIronMelee[irandom(array_length(RadIronMelee)-1)])}} {if MatType="Talloy" {ItemName=(TalloyMelee[irandom(array_length(TalloyMelee)-1)])}} {if MatType="GodRay" {ItemName=(GodRayMelee[irandom(array_length(GodRayMelee)-1)])}} {if MatType="Twilight" {ItemName=(TwilightMelee[irandom(array_length(TwilightMelee)-1)])}} {if MatType="Secret" {ItemName=(SecretMelee[irandom(array_length(SecretMelee)-1)])}}} if LootRoll=2 { {GearType="Ranged"} {if MatType="Scrap" {ItemName=(ScrapRanged[irandom(array_length(ScrapRanged)-1)])}} {if MatType="Wood" {ItemName=(WoodRanged[irandom(array_length(WoodRanged)-1)])}} {if MatType="Stone" {ItemName=(StoneRanged[irandom(array_length(StoneRanged)-1)])}} {if MatType="RadIron" {ItemName=(RadIronRanged[irandom(array_length(RadIronRanged)-1)])}} {if MatType="Talloy" {ItemName=(TalloyRanged[irandom(array_length(TalloyRanged)-1)])}} {if MatType="GodRay" {ItemName=(GodRayRanged[irandom(array_length(GodRayRanged)-1)])}} {if MatType="Twilight" {ItemName=(TwilightRanged[irandom(array_length(TwilightRanged)-1)])}} {if MatType="Secret" {ItemName=(SecretRanged[irandom(array_length(SecretRanged)-1)])}} } if LootRoll=3 { {GearType="Caster"} {if MatType="Scrap" {ItemName=(ScrapCaster[irandom(array_length(ScrapCaster)-1)])}} {if MatType="Wood" {ItemName=(WoodCaster[irandom(array_length(WoodCaster)-1)])}} {if MatType="Stone" {ItemName=(StoneCaster[irandom(array_length(StoneCaster)-1)])}} {if MatType="RadIron" {ItemName=(RadIronCaster[irandom(array_length(RadIronCaster)-1)])}} {if MatType="Talloy" {ItemName=(TalloyCaster[irandom(array_length(TalloyCaster)-1)])}} {if MatType="GodRay" {ItemName=(GodRayCaster[irandom(array_length(GodRayCaster)-1)])}} {if MatType="Twilight" {ItemName=(TwilightCaster[irandom(array_length(TwilightCaster)-1)])}} {if MatType="Secret" {ItemName=(SecretCaster[irandom(array_length(SecretCaster)-1)])}} } }; if LootType="Armor" { {LootRoll=(irandom_range(1,6))} if LootRoll=1 {GearType="Helmet"} if LootRoll=2 {GearType="Upper Body"} if LootRoll=3 {GearType="Lower Body"} if LootRoll=4 {GearType="Gloves"} if LootRoll=5 {GearType="Shoes"} if LootRoll=6 {GearType="Full Set"} {if MatType="Scrap" {ItemName=(ScrapArmor[irandom(array_length(ScrapArmor)-1)])}} {if MatType="Wood" {ItemName=(WoodArmor[irandom(array_length(WoodArmor)-1)])}} {if MatType="Stone" {ItemName=(StoneArmor[irandom(array_length(StoneArmor)-1)])}} {if MatType="RadIron" {ItemName=(RadIronArmor[irandom(array_length(RadIronArmor)-1)])}} {if MatType="Talloy" {ItemName=(TalloyArmor[irandom(array_length(TalloyArmor)-1)])}} {if MatType="GodRay" {ItemName=(GodRayArmor[irandom(array_length(GodRayArmor)-1)])}} {if MatType="Twilight" {ItemName=(TwilightArmor[irandom(array_length(TwilightArmor)-1)])}} };
@jiaskacoding3646
@jiaskacoding3646 4 жыл бұрын
I'm sorry if this is a stupid question, or if the answer is too complicated to explain in a KZbin comment section. I learned to program in Game Maker 1.4, and thus, had no idea that structs were a thing in other programming languages. What are they for? Anything they can do it looks like I could do with a ds map, list, or JSON. Are they less resource-intensive? Should I use them in alongside the aforementioned data structures when making something complex, like a turn-based game? Or is it just about having one variable hold other variables in a quick and easy to read way so that you can slim down global variables(amongst other things)? Sorry, they just look confusing. Thanks for your time.
@GameMakerStation
@GameMakerStation 4 жыл бұрын
That's a lot of questions haha. I suggest you join the Discord server linked in the description and ask in the 2.3-release channel.
@jiaskacoding3646
@jiaskacoding3646 4 жыл бұрын
@@GameMakerStation That's fair. I just have terrible luck with Discord, so I tend to avoid it.
@drothstomp
@drothstomp 4 жыл бұрын
Awesome video man =)
@americantoastman7296
@americantoastman7296 2 жыл бұрын
I'm so confused, wouldnt mySpeed.Add( new Vector2 (100, 10) ); just create a new struct? I thought it was supposed to modify the x and y values of the Vector2 struct by the vec2 value, but the vec2 value is never set? I really cant wrap my head around this at all.
@GameMakerStation
@GameMakerStation 2 жыл бұрын
It should modify the x and y of the mySpeed struct. The only new struct being created is the one passed in as an argument, which is deleted as soon as the function is over.
@adamkruschwitz7692
@adamkruschwitz7692 3 жыл бұрын
Thank you v much, just jumped back into Game Maker after the 2.3 update very confused, trying to use structs based on documentation. Turns out my issue was I defined the struct as a method in the script and not a function *facepalm*
@ksioncdesign7075
@ksioncdesign7075 4 жыл бұрын
thank you for this video
@banish4cost
@banish4cost 3 жыл бұрын
So how do structs work exactly? I could make a parent object with all sorts of structs that do different functions , and then in the child objects i could just call the certain functions so that you dont have to have a bunch of children from that parent? Just the one parent that you can call any function from, for example an enemy Ai??
@GameMakerStation
@GameMakerStation 3 жыл бұрын
Yes, that would be inheritance. You create functions in the parent object and call them in a child object. You can even modify them for each child object - for example, the AI parent may have a function called AttackPlayer(), and all of its children use it, but any particular child (let's say oEnemyBat) could implement it differently (just by defining it again but in a new way). Cheers
@Ver2ion
@Ver2ion 3 жыл бұрын
@@GameMakerStation thank you so much for reply.
@CreaturesOrigins
@CreaturesOrigins 3 жыл бұрын
Is their any downside to making struct member functions static, or should they always be? When tagging a function as static does it lose any sort of capabilities as to what it can do?
@GameMakerStation
@GameMakerStation 3 жыл бұрын
If a function is static, then it will be the same in all of the structs that contain it. So if you just want a constructor to have a function that does something, and you don't wanna ever modify the variable that contains that function, make it static. However, sometimes you wanna make "callback" functions where the function needs to be set from outside the struct, so in that case your function variable should not be static as different structs can have different functions.
@CreaturesOrigins
@CreaturesOrigins 3 жыл бұрын
@@GameMakerStation Wonderful explanation. Thanks so much for the answer!
@CassidyListon
@CassidyListon 4 жыл бұрын
Thanks for the video. I've been using GMS 2.3 for a couple weeks now and the new features are great... but I can't think of a good reason to use structs.
@Goranoful
@Goranoful 4 жыл бұрын
So if I wanted to create a struct somewhere, but use that data in other objects, or scripts, how would I?
@GameMakerStation
@GameMakerStation 4 жыл бұрын
The same variable rules also apply to structs -- you can create local structs, instance structs and global structs, just like variables. You can also use the dot notation to access a struct variable from some instance.
@AndrewOBannon
@AndrewOBannon 4 жыл бұрын
Gml is going the Javascript way
@Evoleo
@Evoleo 4 жыл бұрын
When is it coming? I'm too excited!!
@GameMakerStation
@GameMakerStation 4 жыл бұрын
You can apply for the beta now and you might get in. No idea when the stable version is coming.
@Evoleo
@Evoleo 4 жыл бұрын
@@GameMakerStation I've applied, like, a month ago and I still haven't got a response
@GameMakerStation
@GameMakerStation 4 жыл бұрын
@@Evoleo That sucks, but hey, it's great that you applied early. I'm guessing you might just get in in a few days...
@dbgameace
@dbgameace 4 жыл бұрын
can constructors only inherit from one other constructor or multiple constructors?
@GameMakerStation
@GameMakerStation 4 жыл бұрын
One.
@VICE-H3RO
@VICE-H3RO 4 жыл бұрын
Structs look very useful though here I am still using GMS 1.4 😅
@igorthelight
@igorthelight 3 жыл бұрын
My advice: update to 2 or try Godot. 1.4 is outdated as heck.
@S_Tadz
@S_Tadz 4 жыл бұрын
I'm sorry I left you, GMS, I'm coming back now you've grown up!
@jfurmann
@jfurmann 4 жыл бұрын
awesome!
@gluebluerock136
@gluebluerock136 3 жыл бұрын
Its like object-oriented programming with extra steps
@faridthefadil
@faridthefadil 4 жыл бұрын
this is going to take some time to get used to, never seen a function used as a class before...
@GameMakerStation
@GameMakerStation 4 жыл бұрын
Well, that's the purpose of construction functions! It's a function that creates a struct, so it is essentially a class: it also supports inheritance so you can build a hierarchy of classes.
@akalex770
@akalex770 4 жыл бұрын
Finally!!!!
@professionalquestion5415
@professionalquestion5415 4 жыл бұрын
Can you add these new tools in your lectures for you Udemy courses? So we can learn how to use them correctly for us noobs.
@GameMakerStation
@GameMakerStation 4 жыл бұрын
For the major changes (like Scripts/Functions), I will need to do updates to my Udemy courses so that people don't face issues in 2.3. But of course, I can only do that when 2.3 is out of beta, and into the stable version. I'm also planning to make a new course once 2.3 stable comes out, and will probably do some updates to my Crafting course as well.
@professionalquestion5415
@professionalquestion5415 4 жыл бұрын
GameMakerStation - Matharoo awesome news, I’ll definitely keep them out when you do.
@PabbyPabbles
@PabbyPabbles 4 жыл бұрын
Man when you come from other mainstream languages GML feels like trudging through molasses my project is not even 1% done and I'm already drowning in scripts these changes sound great I'll have to check if you can get default values in functions like in php, fiddling with a bunch of arg count checks at the start of every script is another big turnoff function do_stuff(x, y, n = 3){ } here for example, you have to give do_stuff an 'x' and a 'y' variable, but 'n' is optional and defaults to 3
@hiiambarney4489
@hiiambarney4489 4 жыл бұрын
I dunno with the defaults but the rest is def possible.
@mythology100
@mythology100 4 жыл бұрын
...and liked!
@smallmak5
@smallmak5 4 жыл бұрын
Are structs used in other programing languages or is it gml specific
@GameMakerStation
@GameMakerStation 4 жыл бұрын
"Structs" do exist in some languages, like C++, but I'm not sure what they do there as I don't have experience with that language. However, Structs in GML are much more equivalent to "Objects" or "JSON Objects" in JavaScript.
@saphi20
@saphi20 4 жыл бұрын
GameMakerStation - Matharoo yah, they feel a lot like JSON (good thing :D)
@wheffle1331
@wheffle1331 4 жыл бұрын
Structs exist in C++, but as far as I know they only hold variables and can't have functions. It looks like GML's structs are basically super light-weight GM Objects, seeing as how they can have methods, but exist outside the instance system. Edit: I haven't kept up with GMS lately, and I said a bunch of stuff about how GM Objects can't have methods or functions and that's apparently incorrect now. Pretty cool!
@anixias
@anixias 4 жыл бұрын
Structs and classes in C++ can both hold variables and functions, and even use public, protected, and private keywords. Structs can inherit from other structs in C++ as well. Variables in classes are defaulted to private, but structs default them to public. That's basically the main difference. I know the similarity between them is a big source of confusion for newer C++ programmers.
@princeweekes1
@princeweekes1 4 жыл бұрын
oh the power
@Riversofash
@Riversofash 4 жыл бұрын
These changes seem overwhelming
@EveryCrime
@EveryCrime 4 жыл бұрын
It's very different, but if you start doing it this way you will never want to go back.
@igorthelight
@igorthelight 3 жыл бұрын
Welcome to a proper programming language :-)
@harjiohrg3824
@harjiohrg3824 4 жыл бұрын
he my brother
@LucianoRasente
@LucianoRasente 3 жыл бұрын
se picó!!
@harjiohrg3824
@harjiohrg3824 4 жыл бұрын
HACKING SORRY ITS JOKE
@NoahNCopeland
@NoahNCopeland 2 жыл бұрын
i've watched this so many times and still don't understand it. too many assumptions of knowledge.
GameMaker Sequences (Pt. 1) - Editor & GML Usage
13:12
GameMakerStation - Matharoo
Рет қаралды 24 М.
GameMaker Studio 2.3: FUNCTIONS! (+ Method Scope & Static Variables)
10:10
GameMakerStation - Matharoo
Рет қаралды 15 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
Can You Beat Minecraft From One Grass Block?
35:27
Beppo
Рет қаралды 6 МЛН
Why EVERY Gamemaker dev should use Structs
18:33
RiptideDev
Рет қаралды 7 М.
Optimisation Tips | GameMaker Studio 2
19:10
FriendlyCosmonaut
Рет қаралды 51 М.
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 188 М.
Why I'm Moving To Godot In 2025
14:23
Acerola
Рет қаралды 179 М.
The 15 Commandments of Game Maker
16:32
PixelatedPope
Рет қаралды 125 М.
Organising Data | Menus: GMS2 [P1]
28:19
FriendlyCosmonaut
Рет қаралды 69 М.
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 6 МЛН
Using Variables in GML | GameMaker Pt. 5 (Types and Scopes)
23:07
GameMakerStation - Matharoo
Рет қаралды 5 М.