this video explained constructors in a way the documentation couldnt idk if thats because its 2 am or what but it makes sense now, and now i want to rewrite my struct-based-systems because they are all hard coded, and im currently using a switch statement to cycle between them This is the information ive been needing for my quest system thank you
I find the 'new' operator to be confusing and are specialized for the constructor only. "It is important to note that calling new on any function that has not been flagged as a constructor will cause a runtime exception" -GMS Manual
It's constructing a new structure in memory for you. A normal function usually doesn't do that but just returns the result of that function. So, it's basically easier for you (and the compiler) to distinguish the two when reading the code. Otherwise, a = f() could be either one, which would be more confusing. The compiler enforcing that is a great help, because you can't create an ambiguous situation, which could lead to longer debugging sessions and head aches. So, in the end, it helps you.
@@MaviLeb Thanks for the answer, does this impact performance though? making new structure in memory just for a specific instance every time that instance exists or something
@@salvadorgonzales1 That can't be answered with a general statement, because it depends a lot on how many times you actually create instances. Usually, that should be very fast and not be a problem in most cases. But if you create thousands of instances every single frame of your game, it can get a significant performance issue. Some rule of thumb is that things that only happen when the player presses some button don't matter and things that are processed each frame can be a problem but don't need to be. However, in this case, I'd advice to not think too much about this problem when creating your game. If it makes your code more simple to understand and maintain, that should have a higher priority. The reason is that this problem can be solved by pooling your instances. Meaning, you create some pool of instances which you then re-use whenever you need them. In most cases, this can be implementend without changing your code structure too much after the problem actually shows up. For example for a bullet-hell game like Vampire Survivors you could know that you have some maximum number of any enemy type at any one time in your level, for example 200 bats. So, you could just make a pool (this could be an array for example) of 200 bats which you then re-use every time a bat should be spawned. For this you just change their values every frame. Like, when a bat is killed by the player it is set to be invisible (or not rendered), not destroyed. And when you want to spawn a new one, you get an invisible one from the pool, set their variables back to normal and show it. You can do that for any instance of structures - or any data you have for that matter. There's a free book online called gameprogramming patterns. It has a section about 'object pooling', you can check that out to get a better explanation of the pattern.
New allocates memory for an object. This is how it is done in C++ and C#, and many other languages. Gamemaker is abstracted to the point where it manages memory for you mostly, except for structs
Creating structs is slower than creating arrays but not by too much. So probably don't create them for temporary things every frame. I wouldn't worry too much about using them in general though. They're very helpful and I'm using quite a few of them in my project.
@@GoldScale57 Thanks for the response. I am currently working on a simple RPG game and i have few structs set up that make inventory management a breeze! Also being able to track all player variables inside a single player struct helps a lot.
What games have you made though? Every single person I talk to tells me to do this, or that and they have never made a game. Not even a gamejolt published game. I have published several steam games and never use any of this.
@@georgehennen Hey! So my solo title on steam is called Bitlands, and I’ve composed music for another steam game called Koko: Last Leaf, and Paradigm on itch. My current project Earthward is on steam for select users while in alpha. I’ve also been a programmer and artist for several game jams which you can find on my itch (lots of them can be played via browser, so give it a shot!) my favorites are Lilypad Lowdown and Daisy’s Quest, but there are others as well. (Bitlands was my first ever published game, I made it in highschool)
@@Nicholas-nu9jx Really? Please elaborate or even put a video up on your channel. People keep telling me to use structs so I learned them, now you are telling me this.
@@Nicholas-nu9jx This is essentially saying the concept of classes in programming leads to inefficient code. This is not the case at all. Structs are simply allocated blocks of memory that contain data, actually making them more efficient than objects due to the fact they aren’t managed or put in a render/partition list, not to mention do not have all the properties of an object. If structs in Gamemaker are giving you performance issues, then it sounds like you need to manage your structs better and destroy them when they’re not needed
this video explained constructors in a way the documentation couldnt
idk if thats because its 2 am or what
but it makes sense now, and now i want to rewrite my struct-based-systems because they are all hard coded, and im currently using a switch statement to cycle between them
This is the information ive been needing for my quest system
thank you
It's very nice of you to offer different helpful solutions all the time.
I really enjoy your Terraria Modding series, and videos like these top it all off amazingly
More of these please!!! Subbed
love your videos, hope you come back soon!
Finally! Tell me why! (Oh no, now that song is stuck in my head.)
Thank-you for this!
Could you provide a download for the code in this video? Would love to look into your code for the text boxes
Is it possible you could redo some of the earlier videos in the tutorial series
I find the 'new' operator to be confusing and are specialized for the constructor only.
"It is important to note that calling new on any function that has not been flagged as a constructor will cause a runtime exception"
-GMS Manual
It's constructing a new structure in memory for you. A normal function usually doesn't do that but just returns the result of that function.
So, it's basically easier for you (and the compiler) to distinguish the two when reading the code.
Otherwise,
a = f()
could be either one, which would be more confusing.
The compiler enforcing that is a great help, because you can't create an ambiguous situation, which could lead to longer debugging sessions and head aches.
So, in the end, it helps you.
@@MaviLeb Thanks for the answer, does this impact performance though? making new structure in memory just for a specific instance every time that instance exists or something
@@salvadorgonzales1 That can't be answered with a general statement, because it depends a lot on how many times you actually create instances.
Usually, that should be very fast and not be a problem in most cases. But if you create thousands of instances every single frame of your game, it can get a significant performance issue. Some rule of thumb is that things that only happen when the player presses some button don't matter and things that are processed each frame can be a problem but don't need to be.
However, in this case, I'd advice to not think too much about this problem when creating your game. If it makes your code more simple to understand and maintain, that should have a higher priority. The reason is that this problem can be solved by pooling your instances. Meaning, you create some pool of instances which you then re-use whenever you need them. In most cases, this can be implementend without changing your code structure too much after the problem actually shows up.
For example for a bullet-hell game like Vampire Survivors you could know that you have some maximum number of any enemy type at any one time in your level, for example 200 bats. So, you could just make a pool (this could be an array for example) of 200 bats which you then re-use every time a bat should be spawned. For this you just change their values every frame. Like, when a bat is killed by the player it is set to be invisible (or not rendered), not destroyed. And when you want to spawn a new one, you get an invisible one from the pool, set their variables back to normal and show it. You can do that for any instance of structures - or any data you have for that matter.
There's a free book online called gameprogramming patterns. It has a section about 'object pooling', you can check that out to get a better explanation of the pattern.
New allocates memory for an object. This is how it is done in C++ and C#, and many other languages. Gamemaker is abstracted to the point where it manages memory for you mostly, except for structs
is there any downside to using a lot of structs >=?
Creating structs is slower than creating arrays but not by too much. So probably don't create them for temporary things every frame.
I wouldn't worry too much about using them in general though. They're very helpful and I'm using quite a few of them in my project.
@@GoldScale57 Thanks for the response. I am currently working on a simple RPG game and i have few structs set up that make inventory management a breeze! Also being able to track all player variables inside a single player struct helps a lot.
I use the constructor structs for 99% of the game content i create.
hard
What games have you made though?
Every single person I talk to tells me to do this, or that and they have never made a game. Not even a gamejolt published game.
I have published several steam games and never use any of this.
@@georgehennen Hey! So my solo title on steam is called Bitlands, and I’ve composed music for another steam game called Koko: Last Leaf, and Paradigm on itch. My current project Earthward is on steam for select users while in alpha. I’ve also been a programmer and artist for several game jams which you can find on my itch (lots of them can be played via browser, so give it a shot!) my favorites are Lilypad Lowdown and Daisy’s Quest, but there are others as well.
(Bitlands was my first ever published game, I made it in highschool)
Structs are overrated and lead to cache misses that hurt game performance
@@Nicholas-nu9jx Really? Please elaborate or even put a video up on your channel. People keep telling me to use structs so I learned them, now you are telling me this.
@georgehennen I'll see if I can make a video in gml or find third party sources
@@Nicholas-nu9jx This is essentially saying the concept of classes in programming leads to inefficient code. This is not the case at all. Structs are simply allocated blocks of memory that contain data, actually making them more efficient than objects due to the fact they aren’t managed or put in a render/partition list, not to mention do not have all the properties of an object. If structs in Gamemaker are giving you performance issues, then it sounds like you need to manage your structs better and destroy them when they’re not needed
Why does the text look so terrible?
I used the worst font imaginable.
Hello
hii
sword = mew
hehe
sword= mew item 🗿🗿
What's your discord server?
check Description