I am working on a system to track in-game variables in an RPG, which would be used in events and conditions.
An example would be:
Bob gives you a quest to kill 5 vampires and also visit a shrine in some ruins. Each time the player kills a vampire, the variable “NumberOfKilledVampires” would be increased by one. When he enters a trigger-zone around the shrine the variable “VisitedShrine” is set to true.
When “NumberOfKilledVampires” is >=5 and “VisitedShrine” is true, you get a new dialogue option when talking to Bob, and can report that you completed the quest.
As you can see from the example, I need to keep track of variables of different types (integer and boolean in the example). And though I have a few ideas how to go about this, I am a bit confused as to which is the best. Note, I don’t want to “hard code” these variables into any scripts so that quests, dialogue etc. can easily be expanded without writing new scripts. Rather, the game loads these variables (e.g. from an external file) and then handles them within the framework I am trying to set up here).
Right now I have a system which works but is unsatisfying to me. I am using MULTIPLE arrays of custom classes so that I basically have the following to work with:
IntVariables[0].ID = "NumberOfKilledVampires" //(a string)
IntVariables[0].value = 5 //(an int)
as well as
BooleanVariables[0].ID = "VisitedShrine" //(string)
BooleanVariables[0].value = true //(a boolean).
The drawback is that in events, instead of using a function like
function SetVariableToValue(id:string,value:...)
I have to use
function SetIntegerVariableToValue(id:string,value:int)
function SetBooleanVariableToValue(id:string,value:boolean)
which is quite cumbersome, as I need the respective functions, as well as the individual arrays for all the different data types. I would much prefer to have a single huge array of ALL the variables, independent of the data types of their “value” entry.
The only way I am aware of to make this work is to use String as the data type for all these variables, and have an additional entry “varType” in the custom class to indicate of what type this variable is (for example so that scripts know when to convert the value-string to an integer, so that it can be increased by 1, and then re-converted into a string again). Then, the value of variables could, for example be, “5”, “true”, “7.4” or “Alice”, while the “varType” element would tell the program how to treat/handle this specific variable.
Thus I would have
Variables[0].ID = "NumberOfKilledVampires"
Variables[0].value = "5"
Variables[0].varType = "integer"
Variables[1].ID = "VisitedShrine"
Variables[1].value = "true"
Variables[1].varType = "boolean"
//where all entries are strings
Is this a good idea? Is there a big performace/memory issue resulting from using strings for everything? Is there some other magic solution that I don’t know about?
Thanks for reading through this rather long question!