Getting an Actor's name for an argument

Status
Not open for further replies.

BonnieLass

Veteran
Veteran
Joined
Mar 31, 2016
Messages
41
Reaction score
4
First Language
English
Primarily Uses
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]}});
 

Saelorable

Villager
Member
Joined
Feb 22, 2019
Messages
9
Reaction score
16
First Language
English
Primarily Uses
RMMV
ignore me, i was looking at the wrong function.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
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:

BonnieLass

Veteran
Veteran
Joined
Mar 31, 2016
Messages
41
Reaction score
4
First Language
English
Primarily Uses
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?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
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:

BonnieLass

Veteran
Veteran
Joined
Mar 31, 2016
Messages
41
Reaction score
4
First Language
English
Primarily Uses
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!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,224
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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top