Advertisement
SongJo

Untitled

Apr 10th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. In my excitement following the blog post about the GML updates I started messing around with macros to see what could be achievable in the way of lightweight objects, and functionality for objects in general. And I found a way to get back the built in variables, speed for example, and even the global variable health. I'm not sure if this has been posted before somewhere on the internet, I really doubt I'm the first one to find this. I just haven't looked. And on that, I'm not sure if there are any cons / oversights to these methods that will cause any errors, but it's still pretty fun nonetheless. Just use it at your own discretion.
  2.  
  3. The method is really simple.
  4.  
  5. Step 1.
  6. In the create event of your object, create a variable that will hold the value of the built in variable you want to override. I'll be using speed. This is a variable that I always hated moved the instance by default, taking control away from the user and needing to mend it with variable names like Speed, moveSpeed and breaking the flow of naming conventions.
  7. __speed = 0;
  8.  
  9. That's all, for getting this started in the object.
  10.  
  11. Step 2.
  12. Create a macro. I like to do this in a loose script that never gets called. __initialise() for example.
  13. #macro speed __speed
  14.  
  15. Set the macro speed to the variable you're holding in your objects from Step 1. Mine was __speed.
  16.  
  17. That's about it, you can now use the speed variable freely with your objects without them moving on their own, control is yours. This is quite a hacky way to get around this and I'm not sure what can break with this if that were to happen. My favourite use for this hack though is making health an instance variable as opposed to its default global scope.
  18.  
  19. It's the same as before, __health = 100 in the object's create event. And define the macro anywhere #macro health __health
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement