How do I make NPC attributes in 1 variable?

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I don't remember exactly this is called in programming, I think it's massives. It's when you can put multiple things in a variable. This would be useful for enemy attributes in an RPG or action game, for example, I can put "zombie", "poisoned" and "big head" in 1 variable and let C2 check for those things being in the massive variable, instead of making 3 separate variables, like "Zombie", "Poison" and "HeadSize" with 2 possible values in each, which adds to the already cluttered variable list in a complex project like an RPG. Is there any way to do this?

  • Use tokenat.

    Example: vartext=zombie#9_poisoned#8_bighead#7

    tokenat(tokenat(vartext,0,"_"),0,"#") = zombie

    tokenat(tokenat(vartext,0,"_"),1,"#") = 9

    tokenat(tokenat(vartext,1,"_"),0,"#") = poisoned

    tokenat(tokenat(vartext,1,"_"),1,"#") = 8

    tokenat(tokenat(vartext,2,"_"),0,"#") = bighead

    tokenat(tokenat(vartext,2,"_"),1,"#") = 7

    I used this a lot in my multiplayer CCG and extremely useful in simplifying communication, except that I'm doing it on a bigger scale, which involves 450x46 array. It might seem it will increase the number of event you have to write, but in my case, it reduces amount of event and let me to make a very "compact" loop.

    Have fun

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Example: vartext=zombie#9_poisoned#8_bighead#7

    tokenat(tokenat(vartext,0,"_"),0,"#") = zombie

    tokenat(tokenat(vartext,0,"_"),1,"#") = 9

    tokenat(tokenat(vartext,1,"_"),0,"#") = poisoned

    tokenat(tokenat(vartext,1,"_"),1,"#") = 8

    tokenat(tokenat(vartext,2,"_"),0,"#") = bighead

    tokenat(tokenat(vartext,2,"_"),1,"#") = 7

    Aaaugh! My eyes! My BRAIN! Pain!

    I mean, thank you, but, I don't understand a thing. :/

  • Aaaugh! My eyes! My BRAIN! Pain!

    I mean, thank you, but, I don't understand a thing. :/

    Too bad nobody can shove "understanding" into your brain except yourself and manual is your girlfriend, play with her.

    This technique is usable when you want to simplify/automate thing much further than array, I used this whenever I come across irregular data size and array can't do this without serious logic in place, tokenat simplifies it. Maybe you have to look at array first before using the tokenat method.

  • > Maybe you have to look at array first before using the tokenat method.

    >

    Well, an action RPG has at least from 20 to 100 enemies. Having an array for each of them is even worse than making a clutter out of instance variables. And I haven't heard anything about Instance Arrays. Is there such a thing?

  • Well, an action RPG has at least from 20 to 100 enemies. Having an array for each of them is even worse than making a clutter out of instance variables. And I haven't heard anything about Instance Arrays. Is there such a thing?

    Yes you can do this with a container.

    The other method is, if you currently use 2D array, you can make use of 3D array, it should do the same thing, however this will be quite advanced in a way when you manipulate the array.

  • > Well, an action RPG has at least from 20 to 100 enemies. Having an array for each of them is even worse than making a clutter out of instance variables. And I haven't heard anything about Instance Arrays. Is there such a thing?

    >

    Yes you can do this with a container.

    The other method is, if you currently use 2D array, you can make use of 3D array, it should do the same thing, however this will be quite advanced in a way when you manipulate the array.

    What about enemies that are spawned randomly? Will they position on the 3D array somehow too?

  • What about enemies that are spawned randomly? Will they position on the 3D array somehow too?

    You have to assign the array's z-index to the instance variable of the spawned enemies. As I told you, doing this by array is very advanced, use container if you are unsure how to tackle the array.

  • I don't remember exactly this is called in programming, I think it's massives.

    Never heard of it

    which adds to the already cluttered variable list in a complex project like an RPG.

    I'm not sure why instance variables should be cluttered? Sure if there are repeated variables across many objects you could make it a bit nicer with Family instance variables but otherwise, you have data, you need variables! Be wary of doing 'tricky' things like combining values unless you really need to, because you will trade off ease of use/readability with 'efficiency'.

    I think first thing to try is a 2D array with Y being each NPC 'number' and X being each attribute. 2D arrays aren't too hard. You will need to use '.at() for everything, but you can make this easier with constants such as "HEALTH=0", "XP=1" etc and use these to index into your array columns (X). You can have a npc.number to index into your rows (Y). You can go a step further then and have functions do this for you, e.g. GetHealth( npc.UID)

    I can see by your question "Will they position on the 3D array somehow too?" you must read up and experiment with arrays before tackling them in your game. Good luck and remember, eschew obfuscation!

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