some scripted operations

Currently viewing this thread:

jik

Knight
Ok, may not be needed by many people, but I needed them, so here they are.  I put together 2 scripts (for now, may add more to the thread if I make more).  These are untested right now, since I am in the middle of coding where they are needed, but I thought I'd throw them out there for those that might need something similar.  I'm sure it will spark some ideas for some of the coders out there:

1.  script_party_slot_add
- I made this since I will be doing some basic math (adding/subtracting) with values in slots, and I feel it's a pain to make a local var every time you need to do this.  So why not script it?  If you use it 3 times in your code, you have saved time!  Though I have it for party slots, you can change this to use any tuple object slots.
##script_party_slot_add
##So I don't have to do this manually every time I do basic math in slots
##Usage : (call_script,"script_party_slot_add",<party>,<slot>,<value to add>),
##Input : The party name, the slot, the value to add (negative number to subtract)
##Output: None, slot value will be changed
("party_slot_add",
[(store_script_param,":cur_party",1),
(store_script_param,":this_slot",2),
(store_script_param,":adder",3),
(party_get_slot,":num",":cur_party",":this_slot"),
(val_add,":num",":adder"),
(party_set_slot,":cur_party",":this_slot",":num"),
]
),

2. store_low_random -Based on Rongar's idea (and also added to the updated tutorial, to be released again soon), to get a good short ranged random number (such as from 1 to 10, or 100 to 110 - both have a spread of 10 numbers), take a larger range, the mod the out come to get the range you want.  For instance, if you want random numbers from 0 to 8, you would use mod 9, since the remainder would be from 0 (multiple of 9) to 8 (the highest remainder from mod 9).
##script_store_low_random
##Random generator doesn't seem so random with low numbers.  Rongar's way to fix the issue.  Shouldn't be used for ranges spread larger
##than 20 numbers, but the low end can be as high as you want (ex, 50-65 is a 15 number spread, 80-120 is 40 (to big of a spread!)
##Usage : (call_script,"script_store_low_random",<lower bound>,<upper bound>),
##Input : low end, high end (same as with all Module System ranges)
##Output: the random number is sent to reg0
("store_low_random",
[(store_script_param,":low",1),
(store_script_param,":hi",2),
(store_sub,":spread",":hi",":low"),          ##find the spread range. ex for 50 and 55, the spread would be from 0-5 (+50)
(try_begin),
(le,":spread",20),                        ##make sure that they send a low spread
(store_random_in_range,":rand",1, 271),
(store_mod,":rand",":spread"),            ##will give random from 0 to spread - 1
(val_add,":rand",":low"),                ##move it up to the starting point
(else_try),
(store_random_in_range,":rand",":low", ":hi"),  ##Waste, spread is larger than 20...
(try_end),
(assign,reg0,":rand"),                      ##Outcome is passed to reg0.  Should be used after the script call!
]
),

Neither have real fail safes (though the random will just use the normal random operation on spreads greater than 20), but there aren't any real fail safes in the operations that these mimic either... :wink: 
Just thought I'd share this to get creative ideas going.
 

jik

Knight
I'm sure there will be more.  If you are personally looking for a variation on some of the slot operations or some others let me know, I can give it a poke.
 

Ruthven

Baron
WBM&BVC
Not me, I'm just a beginner.

When I start writing anything other than dialogues and triggers myself, I might have some ideas.  :razz:
 

jik

Knight
Ruthven said:
Not me, I'm just a beginner.

When I start writing anything other than dialogues and triggers myself, I might have some ideas.  :razz:

Funny, some people find dialogs and triggers hard to manage.  :wink:
 

Ruthven

Baron
WBM&BVC
Well, complex triggers I can understand, the biggest triggers Ive written are only about 4 or 5 lines, without counting the starting and ending brackets and stuff.

But dialogues... It's just so simple! Oh well, people's minds work in different ways I guess.
 
Top Bottom