How to use the shop system?
Update 1.6.6 added a script block called Menu Item and a currency named Coins. This page is a guide on how to use them.
Currently the only way to access the shop is by winning or losing.
Coins
To use the coins, just take a number variable and connect it to the Coins
input in the score block.
When you play-test the game you should see the coin counter at the corner of the screen. To get coins just increment the variable you used as the coin counter.
Note: When making a game, you can give yourself free coins to test your upgrade shop. They won't count in the published game though.
Menu items
To add items to the shop, take as many Menu Item blocks as you need, and after placing them in the floor you will see two inputs: a Picture input and a Variable input.
The Picture input is the object that will be displayed for the corresponding item in the Shop.
The Variable input uses a variable to save the current state of the upgrade. You have to use a saved variable (!Var) for this or it'll be completely useless.
There's also other options when you select the block:
Name: how the item will be named in the shop.
If there's no Variable connected to the Variable input then it'll show as a title on a new page.
Buy Limit: this sets the amount of times that object can be upgraded. e.g. say you set it on Max 2; the corresponding object in the shop will max out after two upgrades.
If you leave it in ON/OFF, you'll be able to buy it once, and toggle it on and off. This can be used to activate an extra mode or a cheat code. If the connected Variable is anything but 0, the item is set as bought, skipping the purchase entirely. Setting it to -1 will set it to OFF.
But if you set it to No Limit, the upgrade will have no limit of purchases and you will be able to buy it however many times you want.
Note: "No Limit" comes after Max 100 in that menu.
Price Type: This changes the price of the upgrade after you've bought it.
- Fixed: the price will stay the same, no matter how much you buy it.
- Linear: the price starts at the set amount, and increases by that amount for each purchase.
- Double: the price starts at the set amount, and doubles each time you buy the upgrade.
And you even get a bigger price if you keep clicking after 10 Double! The existing prices are 100, 1k (1,000) and 10k (10,000) and all of them have the same options except for 10k, which only has the fixed option.
Variables
The Variable input in the Menu Item block can only accept number variables, but you can initialize said variable beforehand so that the upgrade starts in a certain level.
If for example you set a variable to 2 before feeding it to a menu item with settings Max 5 and Double 100, the upgrade will then be pre-set to level 2 with a price of 400 coins for the next upgrade.
Playing with the variable isn't as simple as that though. Setting the value of the variable means overwriting it's existing value. One possible workaround is by using the Min and Max blocks. With this in mind you can make your shops more complex and varied; it allows you to have items already set or preupgraded, and can ease testing/debugging.
How to use the bought upgrades
To use the upgrades, just take the value of the variable you used for the item and use it in whatever you need. The variables' values depend on the current upgrade type and it's value. For example:
- If set to "Max n", the variable can be between 0 and n, inclusive.
- If set to "ON/OFF", the variable can only equal -1, 0 or 1.
- If set to "No Limit", the maximum value of the variable depends on your system's maximum exactly-represented integer for floating point numbers. You will never need to worry about this last one, as that number is really big (the maximum unsigned 32-bit number is 4,294,967,295).
Limits
6 pages and 100 items (including titles).
Buggy effects of negative numbers
Negative values do work with other settings besides on/off, but they change the button to look like OFF. They still work, and the algorithm that calculates the price runs like usual. For example, 10 * 2^-2 for 10 Double and other fractions are rounded down, here to 2. Linear Prices will actually give you coins on level -2 and less because of this.