I'm a very lazy person. I like efficient systems.
I plan to store just about everything in JSON objects except local variables. From savedata to databases and so on.
But there are some things that I do not like about the nature of the Construct 3 JSON object. Whenever I want to manipulate a value I have to choose the Set value, Add to or Subtract from event commands from a list of 16 JSON event commands after I first navigated to the JSON object in the object list. And the other thing is that I don't like to type JSON.Get("") all the time.
First I thought about using global json variables inside the script interface. It is very typing-efficient.
Instead of:
- choosing the json object "Data" from the object list
- choosing Subtract from, from a list of 16 json events
- defining the path "defender.hp"
- setting Data.Get("attacker.atk") - Data.Get("defender.def") as the value
I can just type this inside a script:
- data.defender.hp -= data.attacker.atk - data.defender.def
The problem with this is that I would need to update the "Data" JSON object after every change so that I can continue to use event conditions like checking for variables.
So instead I thought I could use a JSON handler function.
When I call the function and put data.defender.hp -= data.attacker.atk - data.defender.def as the parameter/argument the function could translate this into the event system.
But how would I be doing this?
My first guess is to first check for the operation that is done using find(). Then use tokenat() to find the path.
But for the value it gets tricky for me. Because I can not know beforehand if the value just consists of a normal number or if it will need to check 1, 2 or 20 json values. Maybe I would need a loop in combination of tokenat() and every time it finds a math operation ( + - * / ) it creates a local variable and adds Data.Get("") around the argument.
Example from the formula above:
- Function call:
JsonHandler(defender.hp -= attacker.atk - defender.def)
- Function:
find(formula, "-=") > -1 -> Data Substract Data.Get("attacker.atk") - Data.Get("defender.def") from Data.Get(str(tokenat(formula, 0, "-="))
But as I said I'm not sure how I can handle the formulas arguments (example: attacker.atk ; defender.def). What is giving me even more headaches is the fact that the arguments could even refer to other json files.
Like:
Data.Get("defender.hp") -= ( Data.Get("attacker.atk") + Skills.Get("swordslash.dmg") ) - Data.Get("defender.def")
Or is there a whole other way how I could do this?
Thanks for reading! :)
Edit:
Okay after hours of tinkering around I think I found a great solution. I use a JSON handler function but I do it with a script instead of trying it with funky events like from the screenshot above.
The function is very simple and looks as follows:
It just copies the JSON objects, then evaluates the function parameter (the formula) and then copies the data back to the JSON objects.
Here is the simple function call:
And it worked! Screenshot below is from the debugger and after the evaluation/damage calculation.