Adding the number one to a list. What happense? Why when you add the number one another time, the sum equals three?

Hello, guys! I stumbled upon a question that I can not answer so it would be greatly appreciated if someone takes from their time to help a teacher in need. :pray:
The idea of the code is to “collect” a key so the player can open a door only after the player has found and clicked on the key I a chest.
The whole code
If we add the number one to the list Backpack, I guess that the item scepter that we added to it earlier gets replaced by it.



But then why when we add the number one to the previous number one instead of the number two, it equals to the number three?

1 Like

Hello @Chum_Chum !

“change X by Y” block is the same as adding Y to the X, i.e. X = X + Y.
So in your case change Backpack by (Backpack + 1)
is the same as Backpack = Backpack + (Backpack + 1)
That is why when you have Backpack == 1 you get Backpack == 3 after this block.
If you want to just add 1 to the variable then you can simply use block change Backpack by 1. Or you could use the block set variable Backpack to (Backpack + 1)

2 Likes

Thank you @Dmitry! Your answer helped me. Could you also tell me - why when we add the number one to the scepter ([ModelItem[name = “Scepter”;…) it changes to the number one and not just the name of the scepter + 1, i. e. concatenation ([ModelItem[name = “Scepter”;…1)?

@Chum_Chum because arithmetic operations only defined for numbers, if you put any other type of date in it, it will be converted to 0.

1 Like