Object-based Switches and Variables

Status
Not open for further replies.

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
259
Reaction score
117
First Language
English
Primarily Uses
RMMZ
!! UPDATED (Working now: Will attach completed plugin in appropriate section)

-Original post:
So I'm not sure if this should be here or in plugin requests. Basically I wanted to see if anyone could help me as I try to create a plugin that adds "new" functions assigning switches / variables to an object (Specifically the actor in this case).

There are 2 things I wish to accomplish.
  1. Be able to assign, modify, or remove a switch / variable from an actor so my other script "Dynamic Actors" that I'm working on can function a bit better (since it needs certain switch/variable data per actor)
  2. Be able to include this plugin in other plugins (whether for me, or others who wish to use it)
An example might help. Let's take the core RMMV function to set a switch value:
// Game_Switches.prototype.setValue = function(switchId, value)

What I want to try to create is something like this:
// Game_Switches.prototype.setActorValue = function(actorId, switchId, value)

I assume in the Game_Actors class I could create a base parameter as an array.... (referring to Game_Actor.prototype.initMembers = function()):
this._switches = [];
this._variables = [];

And go from there (for loops could grab the proper switches from the array and then use the basic switch.get function to find the value that way... I suppose?) I don't know this is the part where I"m stuck lol. I don't want to overwrite the default Function.setValue() functions, so I'll create new ones for those so I can assign properly to an actor, I just need help in its initial setup.

Then also help on how to include to other plugins?
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I don't have MV with me, but I think you might be able to "fudge" self switches to handle this.

Check what the default code does when it sets and retrieves a self switch, then call that directly yourself, but pass "Actor"+ActorID as the first argument instead of map id.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
An example might help. Let's take the core RMMV function to set a switch value:
// Game_Switches.prototype.setValue = function(switchId, value)

What I want to try to create is something like this:
// Game_Switches.prototype.setActorValue = function(actorId, switchId, value)

I assume in the Game_Actors class I could create a base parameter as an array.... (referring to Game_Actor.prototype.initMembers = function()):
this._switches = [];
this._variables = [];
either you make the object global, at the same level of game_switches, with an extension to handle actors; or, you make it at actor level, with similar functions to the global switches object, but working from the actors object, with no connection to the global switches.

I don't see how you could make switches[id, value] into switches[id, [actor, value]] when the value in switches[id, value] operates by boolean, and the moment you set [actor, value] it'll return true, regardless of the actual value, which can still be false.

the correct form should be to hook everything from the global object, to keep it at game level.
but, for the sake of practicality, you should put it under the actors object.
there is a solution, but I don't see which one could be less twisted when it comes to handling the data
 

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
259
Reaction score
117
First Language
English
Primarily Uses
RMMZ
Well mainly I believe by working in the Game_Actor class I can accomplish most of what I need (I think), but also interchangeably with Game_Switches and Game_Variables. I'm still on some rough drafts at the moment (will upload current work) but I've gone with the decision of making 2 arrays for each.

1st array (switches/variables) will be the IDs respectively while the 2nd array will be their value. Since the declarations are all under the Game_Actor class, then theoretically they should operate when called by that actor? (actor._switches[2] should be the 3rd slot in the array)

=== FILE REMOVED (See first post with updated copies) ===
Review the file for more details of what I'm talking about. Obvious disclaimer is obvious = it's open source, so if anyone completes it before I do, you can claim credit (but I would appreciate an honorable mention).
 
Last edited:

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
259
Reaction score
117
First Language
English
Primarily Uses
RMMZ
EDIT: Nevermind that doesn't seem to work. Seems to be hardcoded within the RMMV engine itself (adding/removing actors updates the Actors.json file)... well I guess that means I will have to modify/alias the Game_Actors object instead.
(( also updated WIP file - attached to first post ))

--------- RETCON --------
Actually (sorry for the double post), but I just had a moment of clarity. What if... we can write "variables" and "switches" into the Actor.json file instead? Like how variables and switches are in the System.json file? Or would that be too complicated? Would the values of said vars/switches not be read properly?

Because I was thinking:
  1. Impose a maximum limit (could be 5000 like the engine defaults, or do a lot less since these are specific to actors)
  2. Setup could be like "variables":[0,0,2] which would mean variable #3's value = 2; means there would have to be a check/filler of all numbers up to that variable (if undefined? null? then input a 0 for filler?) Not sure how the switches would look like in .json file [false,true]?
  3. Then this data could easily be accessed per actor
 
Last edited:

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
259
Reaction score
117
First Language
English
Primarily Uses
RMMZ
YAY! I've done it! Although the script looks like a mess, so I'll finish cleaning it up, add in some plugin commands, and spruce it up for the final touches (will release in the appropriate forum section). Thanks all for the support! <3


// This thread can close now
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
When you want a thread closed, report your first post and let the mods know your question is answered, and they'll lock it.

You might also want to check the forum rules about the double-posting policy (ie - don't do it ;) )

And well done for getting it working! Take a copy of your script before you start doing any cleaning/sprucing - just in case you accidentally break something in the process.
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

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
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,968
Members
137,561
Latest member
JaCrispy85
Top