I have a item in my shop that costs 10 points and my code is supposed to charge the player before it multiplies the price by 1.5 then floor rounds it the code looks like this:
ppc = ppc + 1
print("ppc =",ppc)
msg.post("Button", ppc)
msg.post("Button", "charge_item_2")
msg.post("Button", item_2_price)
item_2_price = item_2_price * 1.5
item_2_price = math.floor(item_2_price)
print("item price =", item_2_price)
ppc means points per click. it should subtract points in another script and then multiply but instead it multiplies firs then subtracts. the subtraction code looks like this
points = points - item_2_price
Messages posted are processed after the update() cycle is completed. So your three messages will be processed after the multiplication and rounding. This is the engine functioning as intended, so you will need to reconsider your logic in this case.
1 Like
Okay but I forgot to mention one thing and that is that I have a shop item that works just fine besides the fact that it subtracts one extra so I just and one to the points it looks exactly the same besides deferent variable names
ppc = ppc + 1
print("ppc =",ppc)
msg.post("Button", ppc)
msg.post("Button", "charge_item_2")
msg.post("Button", item_2_price)
item_2_price = item_2_price * 1.5
item_2_price = math.floor(item_2_price)
print("item price =", item_2_price)
and the subtraction code like I said was subtracting one extra and it looks like this
points = points - item_1_price
points = points + 1
and the whole on message function looks like this
function on_message(self, message_id, message, sender)
if message_id == hash("item_1_charge") then
points = points - item_1_price
points = points + 1
end
if message_id == hash("charge_item_2") then
points = points - item_2_price
end
end
I think that the problem is that the if for the first item runs first but I’m not Shure. this morning I thought of the script sending a message back to the gui and the message would trigger the multiplication and rounding.
I’m having a bit of difficulty following to be honest.
Are you saying an item is charging one more than you expect, and therefore you manually add one back? That’s not a good solution, it means something is going wrong that you haven’t properly understood. You have to fix the root cause rather than the symptoms that you can identify. Otherwise you’re likely to experience other unexplained issues.
Regarding your on_message, a message can only ever have one id so it’s not possible that both those if statements will be executed. It would have to be two separate messages in that case.
3 Likes
Hi I was able to figure out the bug on my own
idk why that item was doing weird subtraction but i fixed it 
2 Likes