I've been trying to figure out how to create a new actor with custom attributes. Unfortunately I just can't get it quite right.
If someone knows or can tell me where to find the exact command and the necessary arguments and format to script a new Actor I would be super happy.
Scripting Actor Creation
● ARCHIVED · READ-ONLY
-
-
define "custom attributes"
everything is indeed translatable into parameters and formulas, but some require more parameters than others. -
Additionally, most commands for actor creation are available by eventing and don't need scripting.
So more details are indeed needed. -
I mean custom values for the existing properties for the Actor class. Which should be:
battlerName
characterIndex
characterName
classId
equips
faceIndex
faceName
id
initialLevel
maxLevel
meta
name
nickname
note
profile
traits
For now, a code sample that creates a new actor with static values would be great. I don't need anything fancy. I'm pretty sure what I need to do is add an Actor class to the $dataActors array. I just keep getting errors.
From my understanding, the built-in events only allow you to add or change an existing Actors. Not create new ones, especially while the game is running. -
You seem to be mixing the concepts.
*Programming languages* define *data structures* that store *data* in memory.
These *data structures* can be further assembled into *objects*, and each *object* open specific *data structures* to the *environment* that we call *properties*, and *properties* can have small processing routines embedded in them that return *values*, which are called *methods*.
Actor *classes* are blueprints that are used to create Actor *objects* based on the *properties* and *methods* they include.
if you want to modify the Actor *class*, you add a *property* or *method* to it.
Or, you can just rewrite it completely and add the properties and methods you want.... the problem is, the rest of the program will still be looking for the original ones and most likely crash.
Adding, you can add whatever you want to a class directly, even in run time, as long as it doesn't affect what's already declared for it that is already running.
If you want to add something without modifying the existing structure, you can *alias* methods, which is basically redirecting the program to run your code and then go back to the intended point before the modification without breaking the original flow.
If you mean to create a new *ACTOR* (character), you can, even directly, and even in run time.
........you just run the corresponding code manually as the interpreter runs it.... just like that.
I believe the simplest skeleton to create a new actor is basically something like:
Code:where $object is the database and index is a non-used slot in the database.chr = Actor.new() chr.property = valueX chr.property2 = valueY chr.property3 = valueZ .... chr.propertyN = valueN $object[index] = chr
you invoke the copy of the Actor class skeleton by Actor.new(), then set up the basic properties, and then copy the finished object over to the database and save it.
(very basic language-generic explanation) -
I think just acting trying to explain what I needed to do helped me out. The code below generated a new actor and added it to my party. Next I'm going to create ways to calculate or determine the values.
child = {
"id":9,};
"traits":[],
"initialLevel":1,
"maxLevel":99,
"profile":"",
"battlerName":"",
"characterIndex":1
,"characterName":"",
"faceIndex":1,
"faceName":"",
"name":"Name",
"nickname":"",
"note":"",
"classId":1,
"equips": []
$dataActors.push(child);
$gameParty.addActor(9); -
"child" is just a hash.
you need *an actor-class object*
"pushing" the hash 'child' into the library $dataActors will throw an error, because they're different objects.
you could potentially just map the contents of "child" to their equivalent of "actor"... there are methods for that.
$gameParty.addActor(9) will just copy actor 9 from the database to the party.
if it doesn't exist, it'll do nothing (or, it'll throw an error) -
Maybe I’ll run into other errors down the road but it ran exactly as intended. It created an actor in the unused actorid 9 with the specified values and then added it to my party once I activated. Since then I changed the 9 in child and $gameParty.addActor() to $dataActors.length and $dataActors.length-1 respectively so it isn’t hard coded. I get a new party member each time I activate the event.
My understanding is that $dataActors is an array of hashes. Each hash represents a different Actor.
I did stop once a new member was added to the party without creating an error. I’ll play around with them and see if any other issues pop up. -
ha ha i would love to help you but i wont, it probably has to do with the fact that i cant... sorry.
-
No worries, I figured this particular issue out. I'm bashing my head over other issues currently haha
-
Exactly. In Javascript it's not called a hash but you get the point.My understanding is that $dataActors is an array of hashes. Each hash represents a different Actor.
Look no further than the actual source of the information, the Actors.json file to see an example:
Code:{"id":1,"battlerName":"Actor1_1","characterIndex":0,"characterName":"Actor1","classId":1,"equips":[1,1,2,3,0],"faceIndex":0,"faceName":"Actor1","traits":[],"initialLevel":1,"maxLevel":99,"name":"Harold","nickname":"","note":"","profile":""}, -
I’m on like day three of JavaScript so I’m still figuring terms out.
I had looked in rpg_objects.js and found similar code. I hadn’t thought to look in the Json though. That would probably make things easier.
I was originally expecting to find a constructor method for the Actor class that I could pass those values. The one I found only seemed to take an actor Id. When I tried that I just got an error saying something about an isAppeared of null. Just adding the dictionary to the array seemed like cheating but it got the job done.
https://kinoar.github.io/rmmv-doc-web/classes/game_actor.html#constructor
This site proved very helpful but I just wish there were some examples.
I figured out how to bring up the console and I’ve been running code ,trial and error, using the interactive interpreter. That’s been a huge help too.