Questions about module_scripts [beginner, kind of]

正在查看此主题的用户

ANTONIVS

Recruit
Hi. I have some questions about module system and python basics.
Module_system tutorials does not include enough information about those things. Command database is also not explanatory as i want.                              #Sorry for bad python&English.

0-  Where is the optimal place to ask those questions?
      If it is not here, I'll appreciate that if you answer my questions here for this time.

1-  Call_script. Can i use this operation for importing a local variable from the called_script to another script?
    I put a local_variable (in the called_script) to x position in (call_script, "called_script", x) but it didn't work as i want. How should i use it?
    What is a (set_trigger_result,) What does it do?

2-  I used a local variable in another script (game_event_sell_item) like this:
      (assign, ":price_factor", reg0),
      (assign, reg1, ":price_factor),
      (display_message, "str_show_price_factor_reg1"),
    It worked.. How come?

3- I can't use a (display message, "@Price factor is {reg1}") properly without using a string.
    If i don't use a string, it shows an irrelevant message in the game. Why?

4- How to use a store_parameter? What is a slot? Is it something global? 
    It would be really great if someone give me the essence of those operations, shortly.


Thanks.
 
1.
Can i use this operation for importing a local variable from the called_script to another script?
Means return result from scripts?
Use registers (reg0-reg..) for that. Well, also WSE has special commands to return values from scripts.

What is a (set_trigger_result,) What does it do?
The game engine expects a result from some triggers and game_function.
set_trigger_result allows to return the results from those triggers or functions.

3. Start a new game. You broke the string order when added in-line strings randomly in the code.

4.
store_script_parameter works in conjunction with arguments of script.
If you call (call_script, "script_called_script", x)
You can get x in  called_script via (store_script_parameter, ":mad:", 1),

Slots — search the forum, it was explained multiple times. Briefly discussed here 
http://forums.taleworlds.com/index.php/topic,56798.0.html




 
0 - The best possible place may be right here. Not what you ask for, but an approximation.
1 - No. All parameters are passed by value.
2 - Because your code is equivalent to (assign, reg1, reg0). Why should it not work?
4 - additional information on slots

插入代码块:
<somewhere else>
  (assign, reg0, 17), # reg0 now holds 17
  (call_script, "script_example_script", 4, reg0),
  # reg0 now holds 21
</somewhere else>

  ("example_script",[
    (store_script_param_1, ":param1"), # param1 now holds  4
    (store_script_param_2, ":param2"), # param1 now holds 17

    (val_add, reg0, ":param2"),              # reg0 still held 17, so holds 34 now
    (store_add, reg0, ":param1", ":param2"), # reg0 holds param1 + param2 = 21 now
  ]),
 
#

Thanks for the really helpful answers!

I started to use WSE a couple of days ago. I used some basic commands, not much. I couldn't find any good tutorials for WSE too. Guess i need to figure out most of them myself. Like everyone does? Anyways.

2-If that script does not mean anything more than (assign, reg1, reg0), how can it display the message which shows price_factor. Sorry, I'm confused here.

That example code was just perfect explanatory Zsar.  Thanks very much.



####################

A couple of months ago, i was struggling with a piece of code. In this forum again, i asked some questions about it. With lots of helpful suggestions i created something. Now I feel, i don't like it.

The code is about getting trade experience with profitable trading. I used the scripts game_event_buy&sell_item. I used the ":multiplier" variables for calculating the profit approximately.

The problem was when i put the item to merchant's inventory, then take it back and put it again and so on.. You know, it's cheating. Cause, the script activates whenever you put an item to merchants inventory, not really when you sell it.

To prevent this, i used a function which makes buy and sell multipliers almost equal, and make another function that add_trade experience with selling, and sub_trade experience with buying.
But that code is far from being perfect.
It is not cool that you lost trade experience when you buy something.


in a nutshell:

What i want is to define what player has before and after the trade in his inventory, to see what items player has sold to merchant.


I think, a code about that, could be very helpful for lots of things about trade.

I've got some ideas. For example, I loot a Vaegir army, then sneaked into Reyvadin. I meet with a merchant and put a looted item to his inventory. And the guy startles, saying Oh my.. dude, what the hell? You..  It's just an example. But i think i can do lots of cool things with that.


Can it be done?
Thanks.

#
 
ANTONIVS 说:
2-If that script does not mean anything more than (assign, reg1, reg0), how can it display the message which shows price_factor. Sorry, I'm confused here.
No, no, what I meant was, that your employ of the local variable be equal to this line.
... Let us try this again:
插入代码块:
       (assign, ":price_factor", reg0), # value of reg0 is assigned to local variable price_factor
       (assign, reg1, ":price_factor), # value of price_factor is assigned to reg1
       (display_message, "str_show_price_factor_reg1"), # a dynamic string is displayed, this string is defined in module_strings.py
Now, the string in question is not part of my Module System, so I do not know how it is defined. Let us assume for this example, that it be:
插入代码块:
("show_price_factor_reg1", "The price factor is {reg1}."),
Then the string would at the time of display_message take the value in reg1 and replace the bracketed entry with it.
So, at the time of display_message, only reg1 is important for the result. reg1 had one line before gotten a value from price_factor and that had gotten its value one line before from reg0. Therefore, the value of reg1 is exactly the value in reg0.
Had the script been:
插入代码块:
       (assign, reg1, reg0),
       (display_message, "str_show_price_factor_reg1"),
Then the value of reg1 would also have been exactly the value in reg0.
Thus, the two scripts are equivalent in effect. Thus the variable price_factor is excrescent.
- Assuming of course, that the effect obtained actually is the effect desired.

Concise: The script does not at all show price_factor. It shows reg1. The two just happen to have the same value.

ANTONIVS 说:
The problem was when i put the item to merchant's inventory, then take it back and put it again and so on.. You know, it's cheating. Cause, the script activates whenever you put an item to merchants inventory, not really when you sell it.
You might want to apply your modifiers in game_get_item_buy_price_factor and game_get_item_sell_price_factor.
Store trade experience gain extra, and then update trade experience in a simple_trigger, say every week or so.
ANTONIVS 说:
What i want is to define what player has before and after the trade in his inventory, to see what items player has sold to merchant.
You can cycle through the inventory using troop_get_inventory_capacity and troop_get_inventory_slot.
To save it, use a troop_slot- or party_slot-array, then iterate the inventory again, seek items in the array (order may have changed) and remove matches from it. All that remains will be sold items.
 
    If what you are telling me is 'circa'; a=b, b=c, then a=c. I know that. If it is something more than that, it's okay. Someday I'll understand, hopefully. Don't bother here more.
#What i was saying there, I used the variable price_factor, in the script_game_event_sell_item which i thought does not have that variable in itself. Now i'm looking at that script again, and i saw minimum_price_factor. I think that's about it. 
What you think?  i)Hello, captain obvios?  ii)no, noo...    Anyways, no urgency for an answer here.

      Again i might've been misconstrued, but...
#I think the game_get_item_buy&sell_price_factor scripts are not what i seek for.
As far as i see, their variable pile there does not include anything about price differences born of city economies et cetera.
I mean;
#When i display the price factor in a message, it shows always the same price for one particular item.
(Yet, it might not be true. But, display_message is the only way for me to comprehend what those codes mean to say.)
-But on the other hand, game_event_sell_item's :multiplier is particularly what i want, i think.
-E.g. If i can buy sausage cheap, from one particular town, it means that buying multiplier for sausage there, is low.
Thence, i want to make player get trade_ex when {he/she} buys an item with low multiplier, and sells it with higher one.
There is a difference with the wise trading and looting. (for the trade experience here of course.)

      Inventory hints seem to be useful. But they're really far from my understanding. I'll keep them, try to find some examples on module system. If you happen to make/come_across some tutorials about those, please let me know. I do seem to have lots of work.

      Thanks for your help and attention Zsar.



 
ANTONIVS 说:
What i was saying there, I used the variable price_factor, in the script_game_event_sell_item which i thought does not have that variable in itself.
Ahh, now I get it (hopefully).
A variable is declared by its first assignment. Assignment operations are all with a "destination"-parameter except for those which modify an existing value, so
插入代码块:
(val_add, ":value", <sourceA>),              # compiler error: local variable value used as operand - A in A=A+B without declaration
(store_add, ":value", <sourceA>, <sourceB>), # declares local variable value and initialises with <sourceA>+<sourceB>
(val_add, ":value", <sourceB>                # local variable value has been declared beforehand and can be employed - no error
ANTONIVS 说:
Thence, i want to make player get trade_ex when {he/she} buys an item with low multiplier, and sells it with higher one.
Well, my idea is this:
  • find two empty slots that all entities which shall accrue trade experience share
    • the first slot be the applicable experience - fetch from here your modifier
    • the second slot be the accumulated experience - add to here the experience gain
  • once per week add accumulated experience to applicable experience and reset to 0
A crude but easy solution, I admit.
Somewhat more complicated, if only the player shall learn:
  • find an empty slot on anything persistent - this be the experience
  • find two empty slots that all entities which can trade share
    • the first slot be the encountered experience - fetch and store experience from and here
    • the second slot be the encounter time - store the current day here
    • when trade is initiated
      • fetch current day and subtract <persistence time>
      • if the day stored in encounter time is not within the so calculated time span, overwrite encountered experience with experience
      • overwrite encounter time with the current day
      • let encountered experience modify all trades
If my conception of the process is correct (which it may not be as I never dabbled in this part), this should keep the prices constant for a limited timespan.
 
Those mighty slots...  I saw the tutorials, I saw your mindfreak. Even though i like it, there is a gap between the tutorials and that one. And i think i'm in the middle of there.

I've got my functions working about how to gain trade experience, the balance between buy and sell etc. Your weekly system idea was what i was thinking also.
Yet, I've got one uncertainty for where to define "the trade experience"
I'm thinking of to put a global variable like "$tradex" Should i do this? If so, where is the best place to put it? I thought (assign, "$tradex", 0), in starting game menus, or starting game scripts.
I've got the sequel fairly i think. Put an operation in sell_item like vall_add, tradex, func(multiplier)...
Or should i not do this? Because of the slot? Can you help me about that please?

 
Not quite sure, what you are thinking at the moment. A draft would be helpful.
ANTONIVS 说:
I'm thinking of to put a global variable like "$tradex" Should i do this? If so, where is the best place to put it?
As long as there be exactly one entity to gain and use trade experience, it is a perfectly fine approach. You can savely initialise it in "script_game_start". Which is also the best place to do that, as it is called by the engine exactly once and right at the start. So there were no chance for your variable to be initialised not timely enough or overwritten later.

Using slots is a variant that could be made to work with n entities, n trade experience values.
... If you plan for traders to "remember" an entities trade experience at the time of their encounter, you will need to employ slots for that. If not, then not.
 
后退
顶部 底部