Tutorial-Blog - Eventing a Trophy Room
● ARCHIVED · READ-ONLY
-
-
That's a really cool way to use the concept I introduced with the node tutorial! There is actually a better way you could do that with an object instead of an array if you're interested.
-
@Trihan If you're willing to share that object way would be awesome. :) I went with the array method because it had been sitting in the back of my head since reading your node tutorial, but another way to do it would be great to know too.
-
I have a similair achievement room, but not in that way though,
but that work on swithes on progress achievement to get 100%
for 1 example, and some others around, but this is also a nice
idea to add =) -
This is a great tutorial, not just for trophies and achievements, but for all kinds of related/collected activities. It's a great application of using javascript to enhance the rpgmaker events. I use arrays a lot, but single element arrays. I can't wait to experiment with an 'array of double arrays. ' And I'm not sure what @Trihan 's node tutorial is all about, but I'm going to read that next. Thanks to all the good people here on this forum who give so freely of their talents and time. :kaoluv:
-
I end up saying this a lot, but... If only this had come a day earlier :D
I'll try this soon! -
Okay, so the basic idea is that instead of having a 2D array where each element is an array consisting of the string representation of the trophy type and the value is the progress, you instead create an object where the trophy type is a property, so you'd have something like:
$gameVariables._data[id you want to use] = { "fishing high score": 0, "butterflies caught": 0 }
Then instead of looping through the array to find a matching string, you'd just do
$gameVariables.value(id of variable you used)["fishing high score"] += 1; -
@Trihan do you use just the {code} on start of the scriptcall?
than a normal variable script or also scriptcall for ._data? -
You need to set _data directly because setValue doesn't like object syntax. I've edited the post to reflect this.@Trihan do you use just the {code} on start of the scriptcall?
than a normal variable script or also scriptcall for ._data? -
so you do those both in scriptcall:
//first on boot to asign them
$gameVariables._data[4] = {"fishing high score": 0, "butterflies caught": 0}
later as scriptcall or as control Variable like
$gameVariables.value(4)["fishing high score"] += 1;
$gameVariables.value(4)["butterflies caught"] += 1;
so when you do in the console log: $gameVariables._data[4]
it would output the 2 object in the array? -
Yep, that's the puppy. You can just do $gameVariables.value(4) after the initial assignment though.so you do those both in scriptcall:
//first on boot to asign them
$gameVariables._data[4] = {"fishing high score": 0, "butterflies caught": 0}
later as scriptcall or as control Variable like
$gameVariables.value(4)["fishing high score"] += 1;
$gameVariables.value(4)["butterflies caught"] += 1;
so when you do in the console log: $gameVariables._data[4]
it would output the 2 object in the array? -
I've read through the last few posts. I've definitely read the words. But what I hear in my head is:
"Flibbertigibbet" -
Nice! :kaojoy:
Objects are OK, it's just that the Control Variables command usesYou need to set _data directly because setValue doesn't like object syntax.evalto interpret the script field, i.e."{ a: 1, b: '2', test: true }"is seen as a {block} containing a misplaced:(syntax error). You can get around this by putting the object in (parentheses), i.e.
◆Control Variables:#0001 achievements = ({ a: 1, b: '2', test: true })
Alternatively you can use a full Script command rather than doing it through Control Variables, e.g.
JavaScript:Note that if you do change variables directly via$gameVariables.setValue(1, { a: 1, b: '2', test: true })_data, it's generally good practice to call$gameVariables.onChange()afterwards, to make sure event page conditions etc update correctly. Might not strictly be necessary in this case, but I thought I'd mention it. -
Ahh, good call caethyril. I knew there was a way to do it but I never thought of parentheses.Nice! :kaojoy:
Objects are OK, it's just that the Control Variables command usesevalto interpret the script field, i.e."{ a: 1, b: '2', test: true }"is seen as a {block} containing a misplaced:(syntax error). You can get around this by putting the object in (parentheses), i.e.
◆Control Variables:#0001 achievements = ({ a: 1, b: '2', test: true })
Alternatively you can use a full Script command rather than doing it through Control Variables, e.g.
JavaScript:Note that if you do change variables directly via$gameVariables.setValue(1, { a: 1, b: '2', test: true })_data, it's generally good practice to call$gameVariables.onChange()afterwards, to make sure event page conditions etc update correctly. Might not strictly be necessary in this case, but I thought I'd mention it. -
is the code: $gameVariables.onChange() the same in MV?Alternatively you can use a full Script command rather than doing it through Control Variables, e.g.
JavaScript:Note that if you do change variables directly via$gameVariables.setValue(1, { a: 1, b: '2', test: true })_data, it's generally good practice to call$gameVariables.onChange()afterwards, to make sure event page conditions etc update correctly. Might not strictly be necessary in this case, but I thought I'd mention it.
and you could still use $gameVariables.value(4)["object"] += 1;
in scriptcall/controll variable?
but also, if you DO
$gameVariables.setValue(1, { a: 0, b: '0', test: true }) on start, what does
the '0' and test: true mean? can test be also any word? -
Yeah, those are just property names and values, they can be anything.is the code: $gameVariables.onChange() the same in MV?
and you could still use $gameVariables.value(4)["object"] += 1;
in scriptcall/controll variable?
but also, if you DO
$gameVariables.setValue(1, { a: 0, b: '0', test: true }) on start, what does
the '0' and test: true mean? can test be also any word? -
Yes. :kaohi:is the code: $gameVariables.onChange() the same in MV?
This works in a Script command, yes.and you could still use $gameVariables.value(4)["object"] += 1;
in scriptcall/controll variable?$gameVariables.valuejust gets a variable's value, it doesn't matter how you assigned it.
For Control Variables, remember that the Script box determines the value to apply to the chosen variable, e.g. if your object is originally like{ object: 5 }, then that script call will return a value of 6. What happens then depends on the chosen operation:
- Set: replaces your object with the number
6. - Add: replaces your object with the string
[object Object]6. - Sub/Mul/Div/Mod: replaces your object with
NaN.
Also, to clarify: by default it is not necessary to callonChangeif changing a variable from one non-numeric type to another, e.g. changing specific value(s) of an array/object. :kaophew: - Set: replaces your object with the number
