Log In  

Lets say I'm creating a game with an item shop that carries only one item (potions for example). I want the user to be able to buy up to 99 potions at a time.

function _init()
cls()
potions = 0
gold = 200
cost_of_potions = 4
buy_potion_amount = 0
end

I want the user to be asked how many potions they want and then they would need to enter it via the gamepad. I know Pico-8 now allows keyboard entry, but I don't want to use that as I want the game to be playable on handhelds like the Gameforce Chi which don't have keyboards. The code would need to check the number of potions the user is buying and compare it to the amount of gold they have and only let them buy the amount if they have enough gold. What would be the best way to implement this? I want it to be easy and quick for the user to enter any of the numbers between 0 and 99. Is there any things I should avoid because they use up to many tokens or are unwieldy code wise? Any suggestions would be appreciated. Thanks!

P#107747 2022-02-27 14:56

1

you could display two number counters, with arrows left-right to move between tens and units, and up-down to change the value. O to confirm and buy!

P#107751 2022-02-27 16:15
1

Cart #two_digit_merchant-0 | 2022-02-27 | Code ▽ | Embed ▽ | No License
1

Hi, @technohat. @merwok has the right idea. See if this code I wrote just now helps.

To load it in Pico-8, type load #two_digit_merchant

I have tried to document the code as neatly as I can. If you have any questions, feel free to let me (or us Piconians) know. :)

P#107766 2022-02-27 19:57 ( Edited 2022-02-27 20:00)

I think that will work! Thanks so much!

P#107767 2022-02-27 20:14
1

@technohat, as Krantor from Blake's 7 once said, "We are sent to help each other. What is this life if we cannot be of some service to our fellows?"

You are more than welcome @technohat. It is my hope my code, suggestions, and articles of interest aid more than just the person I am addressing but other interested Piconians as well.

P#107782 2022-02-27 22:41

@dw817 I appreciate your help. I have one question though. If I wanted to have selecting zero items as a way to exit the shop, how would I implement that in this code?

P#107900 2022-03-02 01:05

Easier still, @technohat would be to use the ❎ button to exit the shop. However to exit the shop all you need to do is change the MODE value to 0 (zero).

However to exit for zero items, you could add to line # 188 just above the END the following:

  elseif btnp(🅾️) then
    mode=0

Here it is in the entirety:

Cart #two_digit_merchant2-0 | 2022-03-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

As the comparison above checks to make sure you have selected at least 1 item to purchase.

To load the new version above, in immediate mode type, load #two_digit_merchant2

P#107901 2022-03-02 01:17

@dw817 Thanks again! That worked! How would you like to be credited in my game?

P#107902 2022-03-02 01:36

That - would be fine, @technohat. Thank you very much. It's ... been a-while.

I know I was credited recently for use of my S2 font in Pico-8 yet - I was not expecting the fellow to just copy my whole program character-per-character merely to display GAME OVER.

Cart #rbgo-2 | 2022-02-17 | Code ▽ | Embed ▽ | No License

Cart #newfont2021-0 | 2021-12-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

https://www.lexaloffle.com/bbs/?tid=45783

But I'll take what I can. :)

In any case, please let me know if you need further help in other areas of your game, @technohat. I am definitely immersed and enmeshed in Pico-8 and happy to assist you.

P#107906 2022-03-02 04:23 ( Edited 2022-03-02 17:39)

[Please log in to post a comment]