Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 15th Mar 2014 at 7:33 PM
Default I want to alter the math in Cyjon's Loan Jar help please
I opened the package file in sim PE and believe I understand where the math calculations occur within the contents however I don't understand how to edit them because the info I'm looking at is like looking at a foreign language. I don't see actual math formulas. I could use some help on what I need to do or a guide that specifically instructs me in the editing of math functions. I couldn't locate a tutorial on here about editing math functions. What I want to do is edit it so that the interest charged is more inline with reality since I have modified the sims lifespans to be longer. So rather than 1 sim day being like a year as it is out of the box, I have changed it so that 20 sim days is a year so sims live for 1,000 days from infant to elder. So the interest charged needs to be 1/20th charged per day of what it currently charges. In behavior functions (BHAV) there is a Function Main and in it is a [private 0x1008] Sub - Calculate Interest (1 arg: Stack Object ID 0x0000). Which is logical to me to contain the math functions to calculate the interest charged per day. But this is as far as I have gotten since the rest of the info show when selecting that item in the list on the left is like looking at a foreign language with no math formulas.

Thanks.
Advertisement
*shrugs*
retired moderator
#2 Old 15th Mar 2014 at 10:34 PM
Hi FonzyBear. Programming languages are in a way different language. BHAVs are no different.

Typically, I suggest people start with Echo's Making Your First Custom BHAV tutorial to get introduced with BHAVs.

Then you might want to read Data Types for Simantics Users.

Usually mathematical functions are performed with the 0x0002 (Expression) primitive. I recommend you use the wizard (the first little square button with the tools on to the right of the operands boxes) rather than editing the operands boxes directly. There you will also see a dropdown list of supported math-related operations, such ">" ("greater than") and "*=" ("Set a value equal to itself times a given value").

Additional reading: Programmer's Guide to BHAVs

I don't mind if you call me "MSD" or something for short.
Tumblr
Perhaps someday I'll have leisure time back...
Test Subject
Original Poster
#3 Old 15th Mar 2014 at 11:54 PM
Quote: Originally posted by maybesomethingdunno
Hi FonzyBear. Programming languages are in a way different language. BHAVs are no different.

Typically, I suggest people start with Echo's Making Your First Custom BHAV tutorial to get introduced with BHAVs.

Then you might want to read Data Types for Simantics Users.

Usually mathematical functions are performed with the 0x0002 (Expression) primitive. I recommend you use the wizard (the first little square button with the tools on to the right of the operands boxes) rather than editing the operands boxes directly. There you will also see a dropdown list of supported math-related operations, such ">" ("greater than") and "*=" ("Set a value equal to itself times a given value").

Additional reading: Programmer's Guide to BHAVs


Clicking on the view BHAV for the [private 0x1008] Sub - Calculate Interest (1 arg: Stack Object ID 0x0000) there are 12 [prim 0x0002] Expression in the list on the left. And on the right is the operands and button you mentioned along with a lot of other stuff we don't need to mess with I assume at this point. I think I may have figured something out though if you will indulge the copy and paste the 12 items to help work through and verify that I'm on the right track:

[prim 0x0002] Expression (Stack Object ID 0x0000 := Param 0x0000) ----- Is making the left equal to the right. Though I have no idea what those two terms are exactly.
[prim 0x0002] Expression (Local 0x0000 := Stack Object's attribute 0x0000 ("Loan Mod 10k")) ----- Same thoughts as with previous.
[prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) ----- Is dividing left term is by 100?
[prim 0x0002] Expression (Local 0x0001 := Stack Object's attribute 0x0001 ("Loan Div 10k")) ----- Same thoughts as with first two of this operand.
[prim 0x0002] Expression (Local 0x0001 *= Literal 0x0064) ----- Is multiplying left term by 100 and then storing the result to it.
[prim 0x0002] Expression (Local 0x0000 += Local 0x0001) ----- Is adding the result stored in the previous step to the left term and storing the result to it.
[prim 0x0002] Expression (Local 0x0000 *= Stack Object's attribute 0x0002 ("Interest Rate")) ----- Is multiplying the left term by the right term and storing the result to the left term.
[prim 0x0002] Expression (Local 0x0001 := Local 0x0000) ----- Same thoughts as with the previous ones of this operand.
[prim 0x0002] Expression (Local 0x0001 /= Literal 0x2710) ----- Is dividing left term by 10,000?
[prim 0x0002] Expression (Local 0x0000 mod= Literal 0x2710) ----- I can't find info on this operand. Do you know what it is?
[prim 0x0002] Expression (Temp 0x0000 := Local 0x0000) ----- Stores the results of the right term in the left term to be passed to [private 0x1006] Sub - Increase Loan (2 args: Temp 0x0000, Temp 0x0001)
[prim 0x0002] Expression (Temp 0x0001 := Local 0x0001) ----- Stores the results of the right term in the left term to be passed to [private 0x1006] Sub - Increase Loan (2 args: Temp 0x0000, Temp 0x0001)

Am I understanding this so far? Now I need to figure out where the terms are getting their values so I can figure out where in this to add the /= expression to divide by 20 the interest before it is added to the loan amount. As I assume this will be the closest I can alter this to mimic real loans.
*shrugs*
retired moderator
#4 Old 16th Mar 2014 at 2:30 AM
[prim 0x0002] Expression (Stack Object ID 0x0000 := Param 0x0000) ----- Is making the left equal to the right. Though I have no idea what those two terms are exactly.
Yes. This sets the Stack Object to the object stored in Param 0 (Parameter 0), the first (and in this case only) value passed to this BHAV

[prim 0x0002] Expression (Local 0x0000 := Stack Object's attribute 0x0000 ("Loan Mod 10k")) ----- Same thoughts as with previous.
Yes. Set Local variable 0 to the value stored in the Stack object's attribute 0.

[prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) ----- Is dividing left term is by 100?
Yes. Take the value of Local 0, divide it by 100, and save the result back in to Local 0.

[prim 0x0002] Expression (Local 0x0001 := Stack Object's attribute 0x0001 ("Loan Div 10k")) ----- Same thoughts as with first two of this operand.
Yes. Storing the attribute into another Local variable.

[prim 0x0002] Expression (Local 0x0001 *= Literal 0x0064) ----- Is multiplying left term by 100 and then storing the result to it.
Yep.

[prim 0x0002] Expression (Local 0x0000 += Local 0x0001) ----- Is adding the result stored in the previous step to the left term and storing the result to it.
Right again.

[prim 0x0002] Expression (Local 0x0000 *= Stack Object's attribute 0x0002 ("Interest Rate")) ----- Is multiplying the left term by the right term and storing the result to the left term.
Yep.

[prim 0x0002] Expression (Local 0x0001 := Local 0x0000) ----- Same thoughts as with the previous ones of this operand.
Yep. Replace the value in Local 1 with the value in Local 0.

[prim 0x0002] Expression (Local 0x0001 /= Literal 0x2710) ----- Is dividing left term by 10,000?
Yep.

[prim 0x0002] Expression (Local 0x0000 mod= Literal 0x2710) ----- I can't find info on this operand. Do you know what it is?
I believe mod refers to the modulo/modulus operator, which The remainder from a division. 4 mod 3 is 1, because 3 goes into 4 once with a remainder 1. 4 mod 2 is zero, because 2 divides evenly into 4 with no remainder. The added equals, like with the previous nodes, is another "do the operation and store the result" command.

[prim 0x0002] Expression (Temp 0x0000 := Local 0x0000) ----- Stores the results of the right term in the left term to be passed to [private 0x1006] Sub - Increase Loan (2 args: Temp 0x0000, Temp 0x0001)
Yep.

[prim 0x0002] Expression (Temp 0x0001 := Local 0x0001) ----- Stores the results of the right term in the left term to be passed to [private 0x1006] Sub - Increase Loan (2 args: Temp 0x0000, Temp 0x0001)
Yep.

I don't mind if you call me "MSD" or something for short.
Tumblr
Perhaps someday I'll have leisure time back...
Test Subject
Original Poster
#5 Old 16th Mar 2014 at 3:29 AM
Ah good I was hoping I understood that much. Ok with some tinkering, since I couldn't follow the chain of values from borrow to final values (as seen in loan info interact). I have found the value that controls the interest amount in the way I need it to change. [prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) Instead of dividing by 100 I divide by 5. This results in the interest on $10,000 borrowed at default 3% rate to be $15 instead of 300%. $15 is the daily interest due on 3% APR of loan value if a year has 20 days (as it does in my sim's world). Anyways, because I changed the literal value in that one expression do I need to change it to match in [prim 0x0002] Expression (Local 0x0001 *= Literal 0x0064)? This local 0x0001 is passed to Sub - Increase Loan which is as follows:

[prim 0x0002] Expression (Stack Object's attribute 0x0001 ("Loan Div 10k") += Param 0x0001)
[prim 0x0002] Expression (Stack Object's attribute 0x0000 ("Loan Mod 10k") += Param 0x0000)
[prim 0x0002] Expression (Stack Object's attribute 0x0000 ("Loan Mod 10k") < Literal 0x2710)
[prim 0x0002] Expression (Local 0x0000 := Stack Object's attribute 0x0000 ("Loan Mod 10k"))
[prim 0x0002] Expression (Local 0x0000 /= Literal 0x2710)
[prim 0x0002] Expression (Stack Object's attribute 0x0001 ("Loan Div 10k") += Local 0x0000)
[prim 0x0002] Expression (Stack Object's attribute 0x0000 ("Loan Mod 10k") mod= Literal 0x2710)

This function is called in two ways. First by the borrow interact with adds X amount to the loan amount. In my testing I'm using borrow 10,000 interact. And second by the results of a day passing at the next 7am time and the Temp 0x0000 and Temp 0x0001 values from Sub - Calculate Interest are passed to it. If that helps identify if I need to change that other expression to match literal values.
Test Subject
Original Poster
#6 Old 16th Mar 2014 at 4:12 AM
Doh I miss posted the expressions in my previous post. The one I altered is as follows: [prim 0x0002] Expression (Local 0x0001 *= Literal 0x0064) to [prim 0x0002] Expression (Local 0x0001 *= Literal 0x0005) and left [prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) as is. I didn't think about it but I could have quickly tested changing both to match before posting to which I did after I had posted. If I change [prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) to [prim 0x0002] Expression (Local 0x0000 /= Literal 0x0005) it does not calculate the correct interest after time has passed. In testing this is what I did: With both values changed I borrowed $10,000 at 3% interest. The loan info showed $15 as expected but after time passed and it reached 7am the first time triggered calculations the loan amount increased to $10,015 as expected but the interest amount miscalculated to $24. Leaving [prim 0x0002] Expression (Local 0x0000 /= Literal 0x0064) as it is the interest calculates correctly again at $15 when loan info is checked in repeating the scenario. So I guess this means I have identified the factor I needed to change and now have correctly altered the mod to function correctly using the new daily interest rate where the interest rate of the mod is an APR instead of a daily rate. Have I overlooked anything?
*shrugs*
retired moderator
#7 Old 16th Mar 2014 at 10:13 PM
Not that I'm aware of, although I haven't really looked too deeply into the mod. Try it and see.

*runs away from financial math*

I don't mind if you call me "MSD" or something for short.
Tumblr
Perhaps someday I'll have leisure time back...
Test Subject
Original Poster
#8 Old 17th Mar 2014 at 5:42 AM
Quote: Originally posted by maybesomethingdunno
Not that I'm aware of, although I haven't really looked too deeply into the mod. Try it and see.

*runs away from financial math*


I appear to have made an error and overlooked something. Changing the one expression by dividing by a factor of 20 means the other expression requires multiplying by a factor of 20. I still have no clue on what values are stored in each variable from the first borrow interact until the interest is calculated and the loan amount modified by the interest at 7am. But I seem to be figuring out the alterations that need to be made. So unless I have overlooked something I believe I have it working now. I did notice that there is a built in flaw (maybe a limitation from the game) there is rounding drift lowering the actual amount due in interest when 3% of the loan amount results in for example 500.50. Though I don't think it is significant enough at this time to worry about it. I'm going to use my testing sim to do a week long test at fast forward to see how it goes.
Back to top