Can I use structures like arrays? How to get nth element of structure?
I cannot use array extension since my game is HTML5 game.
Can I use structures like arrays? How to get nth element of structure?
I cannot use array extension since my game is HTML5 game.
Structure variables was made to be used as arrays too, I think…
Can you provide an example/problem about structure variables, to be used as arrays? Then anybody could take a look and say if there’s a way to be used as array or not.
I am making “dialog engine” for my game, which I’ll use in my future games as well.
I have two arrays: Names and Messages.
Names store character names. Names.1 is name to use in first dialog box, Names.2 second and so on.
Messages store dialog messages. Here it is more complex, because each message is broken internally into lines, so Messages.1.1 is first line of first message, message.3.2 is second line of third message, etc.
Both names and messages are scene variables.
You should use structures as arrays with that syntax :
myStruct[n]
You can have a structure in the structure :
myStruc[n][l]
And, instead of using two structures, you can use one
messages[number].title
messages[number].messages[lineNumber]
How I can set those in scene variables initialization window?
You can set them using actions, but I don’t know how you can do in the scene initialization window.
First thanks a lot victor for your examples
Structures can indeed by used a bit like array by simply naming the children 0,1,2,3…
To create an array directly at the scene startup, in the initial variables dialog, make a right click to add a child variable:
myStruct
|---- 1
|---- 2
|---- 3
You can add child variables to child variables:
myStruct
|---- 1
|----1
|----2
|---- 2
|---- 3
Hm. I kinda already doing it that way, so it is matter of changing few lines of code. Should I use in expression to get string variable, like following (sorry for poor grammar, but I am in a hurry and kinda tired)?
VariableStr(Names[Variable(msgID)])
It is almost correct: The expression between the brackets is a string expression, so you should use this syntax:
Names[VariableString(msgID)]
or
Names[ToString(Variable(msgID))]
to access to the child variable of Names which name is equal to the value of variable msgID.
Thanks!
Out of curiosity, if in msgid there would be string “abcd”, would it access Names.abcd? If so, this would mean we can use structures like dictionaries.
Yes, it’s possible and you can mix both syntaxes :
myDic.test[5]["second"].message
Would it be better to use xml files in that situation?
No need to resort to tables, since markup languages offer the same structures.
It might facilitate greatly future translations (a common text file to translate) and to integrate them ingame (a filename to change).
For saving files, yes. But when you only need it during runtime and/or you don’t want people to modify your game, structures are best choice.