How to improve the use of variables?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have learned some things about instance variables and global ones but I think I am still at a very basic level, I have seen people do very cool things, they use formulas, they create more complex things based on variables and I would like to learn how to do those things.

    I want to have a bigger vision about what things can be done with variables.

    It is not the first time that I see or use variables in a video game creation software

    but for some reason I feel blocked with Construct 3, I literally feel a block in my brain maybe because there is information that I still don't know.

    so if someone has some more advanced tutorials, can summarize their knowledge regarding variables or have some videos would be very helpful.

    I don't have a specific problem with something I want to do and it doesn't work, I just want to learn everything that can be learned about variables and improve the use of them to be able to get things done on my own.

  • It's not about variables, but about: how do you store Data

    Data is like, your character's x position, for example. If you want characters to move, you add 1 to their X on every tick, then it moves!

    But if you want to change your code, you have to go through every single place you wrote the number 1, and change it to 2, if you want to move faster. But what if you change your mind again ? You can create a variable that contains the character's movement speed, so you don'T have to change it every time.

    What if you want your character to only move if you press a button ? You can add a condition, "on button is down" to your code and then your character moves when you press the button !!

    What if you want your character to move the other way when you press a different button ?

    What do you do then? Do you copy and paste your code, but add a - symbol in front of the movement speed variable? What about when you also can move on the Y axis, do you have to write even more code? What about when other objects can move, or can move at different speeds, ??

    Do you instead have the code to move your character be on every tick, and instead change the variable, if no button is pressed, the variable for speed is 0, if the button to go left is pressed, the variable changes to a positive value, and to go right, the variable is changed to a negative value. If you make it this way you don'T have to rewrite your code anymore !!!

    But there's a problem, pressing the moving key moves everything !!! What can we do about that?

    There's this thing called instance variables, every object in construct 3 has "instance variables"

    What if, when you press the button, instead of changing the event sheet global variable, you change a single object's instance variable, then you can use the one movement code only once and move everything independently !!

    What if you want to add acceleration to your code, how would you go about it?

    What would you need to do to be able to do collision detection ?

    Using variables is about thinking about these things, and the more you practice the better you get at it, and you can make more sophisticated systems over time !

    Get out there and make some cool stuff !!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you very much lions_ lions_

    I always save that information for the future, some think that you will never return to them once you read them but you never know.

    and thank you! eleanorjmorel

    That way of explaining things took away the block I had. :D

    Now I see and understand things differently, I have no words to explain it, I can only say that it works and since yesterday I am working with new things, trying and experiencing all those cool things that I saw others do, now I can do them myself.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)