Getting an Actor's name for an argument

Discussion in 'Learning Javascript' started by BonnieLass, Feb 27, 2019.

Thread Status:
Not open for further replies.
  1. BonnieLass

    BonnieLass Veteran Veteran

    Messages:
    41
    Likes Received:
    4
    First Language:
    English
    So I'm having trouble fiddling with a specific plugin, but this is just a scripting question. I'm happy to give you all the details of my plugin usage if you think that will be helpful, just let me know.
    So I have a space for an argument between [ ]. It takes arguments like the following: ["Brown",-27,-0.5,0.8]
    There's a set amount of these arguments that can be inputted. I'm using actor names to store one of them as a string. So if Actor 13's name is the following: "Brown",-27,-0.5,0.8
    When I go to retrieve it for the argument I do something like: [$gameActors.actor(13).name()]
    This doesn't give me the desired result though. The result is like I inputted the default value, which isn't the case.

    Sorry if this question seems ill-put or badly worded. I'm still learning when it comes to coding with Rpgmaker mv. I'm glancing over a lot of context to try and illustrate the heart of the problem I'm having with a script call. This would be a very long post if you wanted to know the full code and it's origin. That being said the plugin I'm using is called Character Creator Ex by SumRndmDde.
    The full script call is this
    Code:
    var id = 2;
    $gameCharacterCreations.addInfos(id, {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/walk/","file":"B1 Crib Rear (1)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/walk/","file":"B1 Body (0)","color":[$gameActors.actor(10).name()]},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/walk/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/walk/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/walk/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/walk/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/dead/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/dead/","file":"B1 Body (0)","color":[$gameActors.actor(10).name()]},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/dead/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/dead/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/dead/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/dead/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/sv/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/sv/","file":"B1 Body (0)","color":[$gameActors.actor(10).name()]},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/sv/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/sv/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/sv/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/sv/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/face/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/face/","file":"B1 Body (0)","color":[$gameActors.actor(10).name()]},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/face/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/face/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/face/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/face/","file":"B1 Drapes (0)","color":[0]}});
     
    #1
    Sauteed_Onion likes this.
  2. Saelorable

    Saelorable Villager Member

    Messages:
    9
    Likes Received:
    15
    First Language:
    English
    Primarily Uses:
    RMMV
    ignore me, i was looking at the wrong function.
     
    #2
  3. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,174
    Likes Received:
    723
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    So...you want to get the actor's name, turn it into the arguments of an array, and return the array? :kaoswt2:

    If so: the name is a string, so the quotes around "Brown" aren't required (though might not affect the result). I'm guessing something like this will work:
    Code:
    JSON.parse('[' + $gameActors.actor(13).name() + ']').map(JSON.parse);
    I think this should:
    • Add opening/closing square brackets to the name of actor 13,
    • Parse the resulting string into an array of strings, and then
    • Map each entry of the array to a suitable data type (number, string, etc).
    [Edit: map may be unnecessary, see follow-up post!]

    Here's details on JSON.parse in case it's helpful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
     
    Last edited: Feb 27, 2019
    #3
  4. BonnieLass

    BonnieLass Veteran Veteran

    Messages:
    41
    Likes Received:
    4
    First Language:
    English
    Thank you Caethyril for understanding the problem I'm having and for helping. That being said I made the changes to the code you suggested and sadly the results did not change except now I'm getting a syntax error that looks like this:
    SyntaxError: Unexpected token S in JSON at position 1
    Here's the adjusted code:
    Code:
    var id = 2;
    $gameCharacterCreations.addInfos(id, {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/walk/","file":"B1 Crib Rear (1)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/walk/","file":"B1 Body (0)","color":JSON.parse('['+$gameActors.actor(13).name()+']').map(JSON.parse)},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/walk/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/walk/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/walk/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/walk/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/dead/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/dead/","file":"B1 Body (0)","color":JSON.parse('['+$gameActors.actor(13).name()+']').map(JSON.parse)},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/dead/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/dead/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/dead/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/dead/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/sv/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/sv/","file":"B1 Body (0)","color":JSON.parse('['+$gameActors.actor(13).name()+']').map(JSON.parse)},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/sv/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/sv/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/sv/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/sv/","file":"B1 Drapes (0)","color":[0]}},
    {"B1 Crib Rear":{"path":"img/SumRndmDde/character-creator-ex/B1 Crib Rear/face/","file":"B1 Crib Rear (0)","color":[0]},"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/face/","file":"B1 Body (0)","color":JSON.parse('['+$gameActors.actor(13).name()+']').map(JSON.parse)},"B1 Eyes1":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes1/face/","file":"B1 Eyes1 (0)","color":[0]},"B1 Eyes2":{"path":"img/SumRndmDde/character-creator-ex/B1 Eyes2/face/","file":"B1 Eyes2 (0)","color":[$gameActors.actor(11).name()]},"B1 Hair":{"path":"img/SumRndmDde/character-creator-ex/B1 Hair/face/","file":"B1 Hair (0)","color":[$gameActors.actor(12).name()]},"B1 Drapes":{"path":"img/SumRndmDde/character-creator-ex/B1 Drapes/face/","file":"B1 Drapes (0)","color":[0]}});
    My actors name is "Brown",24,-1,0.5
    I tried removing the double quotation marks around Brown but this did not change the result. I think the trouble is that I need the double quotation marks to be in the string "Brown". I say this because a script call like this works and has the intended result:
    Code:
    var id = 2;
    $gameCharacterCreations.addInfos(id, {"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/walk/","file":"B1 Body (0)","color":["Brown",24,-1,0.5]}},
    {"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/dead/","file":"B1 Body (0)","color":["Brown",24,-1,0.5]}},
    {"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/sv/","file":"B1 Body (0)","color":["Brown",24,-1,0.5]}},
    {"B1 Body":{"path":"img/SumRndmDde/character-creator-ex/B1 Body/face/","file":"B1 Body (0)","color":["Brown",24,-1,0.5]}});
    I don't see a way of getting the double quotation marks into the string though... Any suggestions?
     
    #4
  5. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,174
    Likes Received:
    723
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Oh, whoops, looks like I may have been a little over-zealous with the .map bit. :kaoslp: Try this instead:
    Code:
    JSON.parse('[' + $gameActors.actor(13).name() + ']')
    That seems to return the array as expected for me via the console:
    Code:
    var name = '"Brown",24,-1,0.5'; JSON.parse('['+name+']');
    >> ["Brown", 24, -1, 0.5]
    Edit: @BonnieLass if that doesn't work then I'll have a look at SRD's addInfos function after I get some lunch, it may be putting it all through another parser. :kaoswt:

    Edit2: @BonnieLass I hunted through the plugin code a bit and it looks like actually it expects a string, e.g.
    Code:
    '[' + $gameActors.actor(13).name() + ']'
    However, to get it to pull and eval values from the code at run-time, I think you'll need to use `${}` notation to mark the evals. Not familiar with the ES6 stuff myself, but perhaps something like this will work?
    Code:
    `[${$gameActors.actor(13).name()}]`
    Otherwise hopefully someone else knows more~
    Or not. :p
     
    Last edited: Feb 28, 2019
    #5
  6. BonnieLass

    BonnieLass Veteran Veteran

    Messages:
    41
    Likes Received:
    4
    First Language:
    English
    Good news! The first bit of code without the .map bit did the trick! Works like a charm! I cannot thank you enough Caethyril for getting me through this! Seriously I'm elated. You put in a lot of effort to help me resolve this issue.

    Problem Solved!
    Please take care and thanks once again!
     
    #6
    caethyril likes this.
  7. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,547
    Likes Received:
    4,121
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #7
Thread Status:
Not open for further replies.

Share This Page