Tutorial-Blog - Eventing a Trophy Room

● ARCHIVED · READ-ONLY
Started by Touchfuzzy 17 posts View original ↗
  1. 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.
  2. @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.
  3. 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 =)
  4. 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:
  5. I end up saying this a lot, but... If only this had come a day earlier :D

    I'll try this soon!
  6. 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;
  7. @Trihan do you use just the {code} on start of the scriptcall?
    than a normal variable script or also scriptcall for ._data?
  8. ShadowDragon said:
    @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.
  9. 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?
  10. ShadowDragon said:
    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.
  11. I've read through the last few posts. I've definitely read the words. But what I hear in my head is:
    "Flibbertigibbet"
  12. Nice! :kaojoy:

    Trihan said:
    You need to set _data directly because setValue doesn't like object syntax.
    Objects are OK, it's just that the Control Variables command uses eval to 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:
    $gameVariables.setValue(1, { a: 1, b: '2', test: true })
    Note that if you do change variables directly via _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.
  13. caethyril said:
    Nice! :kaojoy:


    Objects are OK, it's just that the Control Variables command uses eval to 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:
    $gameVariables.setValue(1, { a: 1, b: '2', test: true })
    Note that if you do change variables directly via _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.
  14. caethyril said:
    Alternatively you can use a full Script command rather than doing it through Control Variables, e.g.
    JavaScript:
    $gameVariables.setValue(1, { a: 1, b: '2', test: true })
    Note that if you do change variables directly via _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?
    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?
  15. ShadowDragon said:
    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?
    Yeah, those are just property names and values, they can be anything.
  16. ShadowDragon said:
    is the code: $gameVariables.onChange() the same in MV?
    Yes. :kaohi:
    ShadowDragon said:
    and you could still use $gameVariables.value(4)["object"] += 1;
    in scriptcall/controll variable?
    This works in a Script command, yes. $gameVariables.value just 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.
    A similar thing applies for arrays. Stick with script calls for changing object/array values!

    Also, to clarify: by default it is not necessary to call onChange if changing a variable from one non-numeric type to another, e.g. changing specific value(s) of an array/object. :kaophew: