Stack object attributes
#1 28-12-2016 
Hello everyone.

I am attempting to tackle a modified version of Cyjons Loan Jar, where you can decide which days of the week it should charge interest. I made a functional object where you toggle it in a BCON, but I'd like to learn how to set it from inside the game to make it more user friendly. Cyjons original lets you set interest from inside the game, but I am having trouble copying him.

Does anyone have any tutorials or such for how stack object attributes works? Or suggestions on how to handle remembering a setting within the object? I've tried to look at some other objects with pie menus that toggles things, like ACR/Visitor controller, but they do it differently than Cyjonsand it's just making me confused.

Cyjons object has declared stack object attribute 2 as Interest Rate in text list Attribs. When you set interest rate via pie menu, the action bhav sets it to param 0. That's all it does. The guardian, from what I can tell, just adds the pie menu options. It does grey out the value corresponding to what stack object 2 is set to, which is done by setting local 0 to 1, and local 1 to stack object attribute 2, and then comparing them. If nothing it adds 1 to local 0 and tries again, until it reaches max interest. When it adds interest it multiplies by stack object attribute 2. What I don't understand is how it's distinguishing from the 10 possible interest % rates. The only place I can see where it's checking attribute 2 to a value is in the guardian, but I don't get how it's then remembering that inside the Sub - Calculate interest.

Action BHAV
[Image: jrfpll.jpg]

Guardian BHAV
[Image: 33p8084.jpg]
Const 1001:0x02 is Min Interest Value, set to 1.
Const 1001:0x03 is Max Interest + 1, set to 10.

Calculate interest
[Image: o558n8.jpg]

If anyone sees what I'm not seeing and can explain it to me I'd be very grateful, or if someone knows of a tutorial explaining how to set things from inside the game and have it remember them Smile
gummilutt, proud to be a member of LeeFish since Jun 2013.

#2 28-12-2016 
From what I can make out of the routine "Sub - Calculate Interest", in order to calculate the actual interest, it needs the interest rate that was defined (in an attribute) on the specific Jar that you selected the option from. To gain access to this attribute, it needs an object ID in the variable "Stack Object ID". The object ID would be the unique value that identifies a specific Loan Jar: the one Jar that you selected the option on. Param 0x000 is probably initialized (either by the game engine itself, or by the BHAV that *called* "Sub - Calculate Interest") to hold this object number.
Once line 0x0 (0) has copied the value in Param 0x0000 to Stack Object ID, the system can then read the attributes from that object. Note that there is no method to read attributes directly from a Param, a Temp or a Literal, ONLY from "Me" or "Stack Object".

That's all that I can give you with such limited information. I might need to DL and inspect the Loan Jar if there is any more specific stuff you require...

#3 28-12-2016 
Thanks BO, I appreciate it. Sub - Calculate Interest is called by Function Main. It starts by setting Stack Object ID to My object ID, then idles and at 7am it runs Sub - Calculate interest, followed by Sub - Increase loan, and then back to idle. I think I understand what you are saying and how it's doing it, I'll make another attempt when I get back home tonight and see if I can get it to work.

Should anyone want to take a look, I'll leave a link to the loan jar Link to loan jar

#4 28-12-2016 
Ah yes, ofcourse. I now remember what happens.

When a BHAV is called, the system may overwrite things like 'Stack Object ID' and 'My Object ID' with certain values that are determined by the system. So when one BHAV calls another, it automatically - as a precaution - copies the contents of 'Stack Object ID' into 'Param 0' first. The BHAV 'Sub - Calculate Interest' simply copies that value from 'Param 0' back into 'Stack Object ID'.
And because 'Main' has first copied 'My Object ID' into 'Stack Object ID', this is how 'Sub - Calculate Interest' knows which jar it is working with.

#5 29-12-2016 
Right, that makes sense. But the question remains, where and how does choosing say 5% in the pie menu get "set" inside the object? I get how guardian bhav is checking to see which option it should gray out and which it shouldn't, but I don't understand what it is that stack object attribute is holding to make it know when local 0 == local 1. Is it adding a numerical value? Is it remembering the pie menu path and checking which is grayed out? How does it know what pie menu option is in effect right now?

#6 29-12-2016 
Ah, I see that I'll need to have a look at the object itself in order to solve your mystery. Please allow me a minute to SimPE it Smile

Edit to add: Ah yes, ofcourse. That's how this worked...
The Guardian not only determines which options are open, it also *creates* the options in a sense. When a guardian BHAV creates multiple options in a sub-menu pie (using the "[prim 0x0032] Add/Change the Action String" function), each of the options is given a number, depending on the parameter given in the instruction - in this case, Local 0x0000, which is 0 for 0% interest, 1 for 1% interest, et cetera. When you SELECT one of the options, the corresponding number is stored in Param 0, and passed on to the action BHAV.

In the case of a Guardian BHAV and Action BHAV, the system has automatically already set Stack Object ID to the object ID of the specific object - in this case a jar -, so its attributes can be properly addressed.

Here, the Guardian BHAV simply reads the Stack Object's attribute 0x0002 to find out which option it must grey out, and stores it in Local 0x0001. In Local 0x0000, it sets up a loop to cycle through all the menu options. Before actually creating each option, it tests if Local 0x0000 is the same as Local 0x0001. If it is, it runs line 0x4 to create the greyed out option. Otherwise it runs line 0x5 to create a clickable option. (Select each of these two lines and check at the right, you'll see that they're set to different modes...)
As said earlier, the options will be numbered in the order they are created by the Guardian BHAV, regardless which of the [prim 0x0032] lines is used. Once you've picked your option, the Action BHAV will use the number - which was passed on through Param 0 - to set the value of Stack Object's attribute 0x0002, the third attribute of the Jar you selected the option on.

#7 29-12-2016 
You're right, BoilingOil. I've messed up in the past with "add pie menu string" and it's totally that.

Two options in your test / guardian BHAV :
- you set the Stack object ID to a chosen number for each pie menu (so that later you -the modder- know the number that goes with each pie menu)
- you use a loop in a variable (here it's in local 0) and you add 1 for each pie menu (here it's a little different because it seems to check an attribute 0x02 in line 1 of the BHAV > 'BHAV calculate interest' do the calculation and store it in temp 0, then that temp 0 is probably stored in attribute 0x02 in another BHAV) and store it in Stack Object ID, so that it can be linked to the pie menu string. The modder can't know the number linked to each pie menu string. However, the player can see this numbers because the pie menu string use "§local" (= the current number in the local variable when the specific pie menu string is added). It could go on forever and you would have x pie menus and it would bug the game, but the last line in the BHAV sets a limit : the local 0 can't be a number superior to the value in constant 1001 0x03. When there's no numbers left, the loop is cut, by returning true.

For the two options, as it was said by BoilingOil, the value of the pie menu string clicked by the player (= the current value in Stack object ID) is stored in Param 0. And voilà !

#8 29-12-2016 
Thanks a ton both of you! That solves the mystery of what I wasn't seeing. I knew Cyjons code works so yesterday I tried just copying his method to see if it would improve things, but I am having trouble re-purposing the pie menu part to what I want to do. Cyjon has 1-9, you pick one and that is grayed out. If you want to un-set a number, you pick a different one. I want to add an on/off for each week day, so I'll need to figure out a way to have two values where only one activates interest. I'm sure it can be done, I'm just having trouble seeing how, but I think a few more re-reads of your posts and looking at code it should start to make sense. Thanks again both of you, especially you BO for taking the time to look at it in SimPE. I really do appreciate it Smile

#9 29-12-2016 
@gummilutt If I may advise you here, I suggest that you do NOT mess with the interest setting in order to turn it off for certain days. Because if you were to do that, you would have to set the interest rate for every single day individually. You would need to use more attributes than you have available.
Instead, make a new menu in which you can switch each day on or off. When the interest for today must be calculated, you first check if today has been switched on. If so, then you do the calculation. But if not, then you simply jump straight to the end and exit, assuming that you're done!

Also, don't feel bad about not seeing it before. When I was first confronted with the need to set up dynamic pie menus and sub-menus, I was totally baffled as well. But once I realized what was going on (with some help of other known modders, of course), I soon set up some rather complicated menus myself. You should look at my "Spawn Objects" and "Need Freak" mods for some interesting examples.
Need Freak is especially heinous, because at no point anywhere in the process, it seems to be clear what option is being created. Look for example at the BHAVs "Setup - TEST" and "Sub - Setup - TEST". I know that together, they create over 90% of the entire pie menu and its sub-structures, but I find it extremely tough to figure out what I'm doing there, and I'm the one who MADE that!

@ankoyume You're right... I missed the step of putting the value in the Stack Object ID before calling the MakeAction primitive. Thank you for completing me on that part. Big Grin

#10 30-12-2016 
My pleasure Tongue


Sorry, that is a members only option