Nice work, a true classic.
Mikal Thank you!
How was it integrating the JS into C3, any special tips or tricks along the way?
I used JS to manage the math part of the game. I left the graphic part to C3.
For example, to check that the insertion of values is consistent I used js
To show the screen writing I used c3
A useful trick, even if fairly trivial, was to use a global object to pass some values between C3 and Js.
To pass the values I used two JS functions: getValoreVariabile, to get the value.
function getValoreVariabile(runtime, nomeOggetto, nomeVariabile, position = "first") {
if (position == "first") {
const obj = runtime.objects[nomeOggetto].getFirstInstance();
return obj.instVars[nomeVariabile];
} else {
const obj = runtime.objects[nomeOggetto].getFirstPickedInstance();
return obj.instVars[nomeVariabile];
}
}
And setValoreVariabile, to set the value.
function setValoreVariabile(runtime, nomeOggetto, nomeVariabile, value, position = "first") {
if (position == "first") {
runtime.objects[nomeOggetto].getFirstInstance().instVars[nomeVariabile] = value;
} else {
const array = runtime.objects[nomeOggetto].getPickedInstances();
array.forEach(function(obj) { obj.instVars[nomeVariabile] = value; });
}
}
For example, to print the player's statistics, I first calculate everything to JS
const value = hamurabi.ReportPlayer();
Then I pass the value to an object c3
setValoreVariabile(runtime, "HAMURABI_PERSISTENT_MEMORY", "HAMURABI_log", value);
And finally I leave to C3 the task of writing on screen.
-> txtLog: Typewriter text HAMURABI_PERSISTENT_MEMORY.Log over 3 seconds