Hello
I'm sorry if this is a very noobish question, but i'm having a hard time understand arrays in general, so here goes.
I'm trying to make a "trait" system, with different ranks, so say your character has 3 levels of a given trait, namely "Strength", which goes like this "nStr, Str1, Str2, Str3", where nStr represents not having the trait at all.
How could i include something like this in an array, so i can merely print all of your characters traits in one go, like a list? example: $traitlist
If we say that there also exist a leveled traits for Dexterity and Intelligence, then a printed example would look something like this:
Traits = $traitlist ==> Traits = Str2, Dex1, Int3
and in case you had nStr (which is not having the trait at all, then it would look like this:
Traits = $traitlist ==> Traits = Dex1, Int3
It would also be fine if there was an way to make an array where you could just throw in objects and take them out. I am not too keen on widgets, and i would very much appreciate it if it was kept simple.
Thank you very much.
ps
I read the Sugarcube document, but couldn't find anything helping with something like this.
Comments
Add an element to an array:
What you probably should be using is a datamap:
If you want to just have it all regulated with a single array, it would have to look something like:
$traits now gives you: Strength, 0, Dexterity, 2, Intelligence, 4
You'd have to use a <<for>> macro to accomplish what you want to do:
That seems a bit overcomplicted to me though.
<<set $character.str += 1>>
and i guess simply printing out all numbers would be $character
Do you think i could do this with strings as well?
like
<<set $character to {
"str": Strong,
"dex": Dextrous,
"int": Intelligent
}>>
and if i wanted to change the str string i would just <<set $character.str == "Very Strong">>
Thank you a ton!
I'd still use datamaps, just because it will make it a lot more easier to reference your characters traits in your text if you have track the stats of more than one character and it will make it a lot easier to work with loops, <<for>> macros and widgets once you get accustomed to using them.
Luckily using widgets is a lot easier than you might think. You just create a passage for your widgets, give it the tag "widget" and then you all you'd have to say would be something like:
Basically the text you want printed, whenever the status is shown. Now, whenever you type <<status>>, Twine will print out all stats as set up within the widget, like for example:
I have been using numbers in my earlier example, since that will make it a lot easier if you want to implement the stats into something like a combat system, e.g.
If you have different uses for your stats, you can go with strings instead of numbers, but you'll have to use quotation marks:
Each number will point to an index in the array, starting at 0, so the two systems should match up very nicely.
For printing everything, you can use a second array containing the keys to create a <<for>> loop:
That's a good idea, but if we want to do this, we should probably use something like this:
We use the <Number>.clamp(min , max) method to make sure that the numbers that represent our stats will stay within the bounds of the corresponding array.
No. '==' is a comparison operator. The assignment operator is '=', or 'to'.
I'd think that it would make more sense to use <Number>.clamp() during assignments, so you never have to worry about your values being out of range in the first place.
Depends on what game mechanics we're aiming for - Whether we want the character traits to be able to go beyond the boundaries by some means or to be always within the strict limits.