Using Actions

Started by Ryex, November 04, 2011, 08:40:16 pm

Previous topic - Next topic

Ryex

ok, here is how actions will work.
each action will be registered as a component in the kernel. you'll get the action and create it.

most of the default actions are created by passing an id and a hash of parameter names to the new values you want them set to {"name": "bobsword", "atk": 10"}

in the case that the paramiter's value is a non simple object like a number the action will create a sub action in which case that name in the hash will need to be mapped to a structure of information used create the sub actions.


in the case of a table you need to pass a list of hashes where each hash is the hast used to create a table action (all existing actions need to be edited to use this behavior, take a list of hashes for parameter that are tables and creat a TableEditAction sub action for each one)

the hash should look like so.

{"dim": int, "index": int, tuple, or list, "value": value} or if your resizing the table {"resize": True, "shape": tuple or list}
if resize is true the action is a resize action and all other data related to setting a value is ignored

now for what these value should be
"dim" : an int that is the dimension of the table your editing 1 for 1d 2 for 2d and 3 for 3d
"index": the index of the item to edit, can use a slice. it can only be an int if the dim is 1. if it is a tuple and the dim is 1 it is assumed to be a slice. if the dim is more than 1 index must be a tuple or list of ints and tuples or lists of the length dim. where each item is a x, y, or z component of the index of the item to edit. each item can be a tuple or list to use a slice. tupels or lists used to describe slices to take can be one or two elements long. 2 for a simple start end slice, and 3 for a start end and step slice. ie an index item of (0,10) would be equivalent to the slice [0:10] and (0,10,2) would be equivalent to [0:10:2] None may be used to leave values out. so a index item of (None,10, None) is [:10]. see a tutorial for slicing sequences in python for more detail. see the numpy documentation fo details on sepecial indexing in numpy

please make yourself familiar with slicing as it is much faster than looping over each item especially in numpy
"value": the value to set the index or slice to see numpy documentation for the behavior this will present
"resize": True or False, default is False. if True overrides the above values and makes the action a resize action which called the resize method on the table and stores the shape it was before
"shape": list or tupel of the arguments to be passed the the table resize method


for example an actor action may look like this
actor_action = KM.get_component("ActorEditAction").object
data = {}
data['name'] = "Bob"
data['battler_name '] = "000-bob"
data['weapon_id'] = 152
table_data = {}
table_data['dim'] = 2
table_data['index'] = (0, (1,100))
table_data['value'] = [500+x*50 for x in xrange(1,100)]
data['parameters'] = table_data
action = actor_action(actor_id, data)
action.apply()
this would set the actors name to bob, it's batter image name to 000-bob, it's weapon id to 152. and set the values of the the actors hp to 550 at level 1 adding 5 each level until it was 5450 at level 99. or in other words the default hp values on creating a new actor.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

How is this going to be on RAM usage, especially with larger objects like maps, etc?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

shouldn't be to high, but we will have to implement a stack limit on the number of undos available that the user can raise or lower just to make sure it doesn't get too high. the table only stores the actions only store the values you edit.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

I also suggest that you don't hardcode action type names but have a list of constants for that (then you wouldn't actually even need strings but can use numbers, even though strings work as well). It's just too easy to make a typing mistake somewhere and create unnecessary bugs that could have been avoided.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.