New game - code advice regarding Wealth/Currency

This how I would approach it.


*label shop
What would you like to buy?
*choice
 #Dagger 5sp
  *set cost 5
  *gosub convert
 #Sword 1gp
  *set cost 100
  *gosub convert

*label convert
*if (gold=1)
 *set silver +100
 *set gold -1
 *goto convert
*if (cost=>silver)
 *set silver -cost
 *gosub conv_so
*else
 Sorry you do not have enough coin
 *gosub conv_so
 *return

*label conv_so
*if (silver=100)
 *set silver -100
 *set gold +1
 *goto conv_so
 *return
*else
 *return

Have not tested but should work.

@FairyGodfeather
interesting idea, it would simplify it in the aspect of shopping. but I am not quite sure how to do a temp. conversion for the display in stats.

Several games use currency, but I haven’t seen any that uses it in multiple levels. the ones I have seen all use “Gold”, as the only one, which is quite simple to do.

However, I feel that I can add more depth to the currency system with it being in both gold and silver.

I will try to look into the whole *temp thing, it does sound very promising, and something I hadn’t thought of myself.

Thank you for the input, and if you have any ideas on how to do it, it would be much appreciated.

@lordirishdas

Very nice, I will give it a go =)

Your welcome, hope it helps. Of course this is just rough codeoff the top of my head. I am sure it can be refined or written better.

I’d think using silver as the only real variable is really simplifying you’re job for currency, without devaluing your gold & silver depth. Plus, you’re using base 10, so it’s simple enough to do, I believe.

Your regulater (sic) is pretty good, and you can retool it to simplify coding.

E.G.

choicescript_stats.txt


*temp gold
*label wealth_regulator
*if silver>99
  *set silver - 100
  *set gold + 1
  *goto wealth_regulator
  *comment
*if silver<100
  *goto finished
  *comment Sorry about this bit of code. Vanilla forums hates us all equally.
*label finished
*comment Since you're using levels of currency, I'd recommend opting out of a stat chart for currency - it looks a little funny in my head.

Gold: ${gold} Silver: ${silver}

*comment Side by side makes sense to me, as opposed to Gold on one line, and Silver on the one beneath it. They serve the same purpose, why be on separate lines.

Shop Idea?


*set silver 150
"Lookin' to buy iron or steel?"

*choice
  *selectable_if (silver>50) #Iron Sword - 50 Silver
    The man takes 50 of silver coin. 
    You receive an Iron Sword in return.
    *set silver - 50

  *selectable_if (silver>150) #Steel Sword - 1 Gold and 50 Silver
    You give the man a gold coin and 50 of it's silver cousins.

    He gives you a Steel sword in return.
    *set silver - 150
    *comment Players should believe that it's taken away 1 Gold and 50 Silver, but really it's taken away just 150 silver. The wealth_regulator will still show that it's taken 1 Gold though.

  #Nevermind. I should save my coin.
    You decide to leave empty-handed, but purse-full.

For future reference, try not to double-post while your Edit button is available and if you’d prefer to type out codeboxes, use the tags < pre > and < /pre >, removing the spaces.

I’ve thought of doing this before but thought it wasnt the smartest move later on, mine would of looked something like this.


*label countup
*if (bronze >= 100)
  *set bronze - 100
  *set silver ++
  *goto countup

*if (silver >= 100)
  *set silver - 100
  *set gold ++
  *goto countup

You have ${bronze} Bronze, ${silver} Silver, and ${gold} Gold.

I may have overlooked some stuff, but I would of put mine in the choicescript_stats but everytime someone got money in the game I would copy and paste the converting part over, so it doesnt have any errors.

Edit: And Damn Cad beat me to it :confused:

You may be able to use the modulo operator to simplify all these even more: http://en.wikipedia.org/wiki/Modulo_operation

“You can also use the modulo operator “%” to calculate the remainder after taking a division. Modulo is pretty weird, but it’s has two particularly interesting uses. First, you can check whether a number X is evenly divisible by a number Y by checking whether X % Y = 0. Second, you can use it to get the fractional part of a number X, the stuff that comes after the decimal point, by calculating X % 1. For example, 3.14 % 1 = 0.14.”

  • Advanced Choicescript Guide

@CJW could you provide an example of how that can be used? It’s melting my brain currently looking at it. How could you use it in the example to convert gold into silver?

@FairyGodfeather, I tried to figure it out, too. All I could get out of it was that, if you have 563 silver, you could *set silver % 100 and it would end up being 63 silver. I don’t know how to translate that removed 500 into 5 gold.

@Caddmuss I already read that. :slight_smile: Actually I read it when I was trying to work out how best to help earlier but I couldn’t make head nor tail of it. My brain’s being math stupid today.

Ooh, I just figured out a random idea for this if you’re doing the multi-level currency!


Whilst traveling through the wood, a band of thieves emerge from the brush.

"Hand over your coin purse, or die."

No way to defend yourself, you toss over the small pouch of currency.

The leader pockets all your gold before tossing you pack a still partly filled sack.

"Have a drink on me when you get out of the forest," he smirks.

*set silver % 100

It’s just off the top of my head, but at least I can think of a use for modulo operations now.

Um. Not sure if this is precisely right. I was fiddling with the tester though and it kind of seems to work.

In this case I’m using wealth as the variable for how much money you have. It’s in silver. I’m using the silver and gold variables just to display to the player how much cash they have and calculating it off their wealth stat.


*create wealth
*create gold
*create silver

*set wealth 281

*set silver wealth
*set silver % 100

*set gold wealth-silver
*set gold gold/100


Wealth: ${wealth}
Gold: ${gold}
Silver: ${silver}

Thank you very much all, I have gotten it to work beautifully, now I just need to make an inventory system =)
Here is my final product.


*choice
	#Let's go shopping.
		*gosub merchant
	#I'll just quit now
		*finish

*label merchant

*set converter_1 true

*label converter_1
*if (converter_1 = true)
*if (Silver >= 100)
	*set Silver -100
	*set Gold +1
*if (Silver >= 100)
	*goto converter_1


You currently have: ${gold}Gold and ${silver}Silver

*set converter_1 false

*label converter_2
*if (Gold >= 1)
	*set Silver +100
	*set Gold -1
*if (Gold >= 1)
	*goto converter_2

What would you like to buy?

*choice
	*selectable_if (Silver >= 5) #A Dagger for 5 Silver
		*set silver -5
		You have purchased a Dagger
		*goto merchant

	*selectable_if (Silver >= 100) #A Sword for 1 Gold
		*set silver -100
		You have purchased a Sword
		*goto merchant

	#I which to venture forth
		*return

I have kept this in my stats aswell, it always shows the correct amount in gold and silver, even when shopping.


*label wealth_regulater
*if (Silver >= 100)
	*set Silver -100
	*set Gold +1
*if (Silver >= 100)
	*goto wealth_regulater

Any adjustment advice?
Or general advice regarding inventory management?

I have a 8 slot inventory coded but it’s pretty advanced but ill post it for you.


\*create pocketspace
\*set pocketspace 0
\*create backpackspace
\*set backpackspace 0
\*label inventory

\*line_break
\*if (backpackslot1 != "Empty")
  \*set pocketspace + 1
\*if (backpackslot2 != "Empty")
  \*set pocketspace + 1
\*if (backpackslot3 != "Empty")
  \*set backpackspace + 1
\*if (backpackslot4 != "Empty")
  \*set backpackspace + 1
\*if (backpackslot5 != "Empty")
  \*set backpackspace + 1
\*if (backpackslot6 != "Empty")
  \*set backpackspace + 1
\*if (backpackslot7 != "Empty")
  \*set backpackspace + 1
\*if (backpackslot8 != "Empty")
  \*set backpackspace + 1
  \*line_break

\*if ((backpack) and ((pocketspace = 0) and (backpackspace = 0)))
  You do not carry anything with you.
  \*fake_choice
    #Go Back
      \*goto_scene choicescript_stats

\*if (backpack) and (pocketspace >= 1)
  ----------Pocket----------
  \*line_break
  Pocket Space: ${pocketspace}/2

\*if (backpack) and (backpackspace >= 1)
  ----------Backpack----------
  \*line_break
  Backpack Space: ${backpackspace}/6

\*if (pocketspace > 0)
  \*fake_choice
    \*if (backpackslot1 != "Empty")
      #${backpackslot1}
        You open up your pack to grab your ${backpackslot1}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot1 = "Meal")
            #Eat ${backpackslot1}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot1 "Empty"
                \*goto display
          #Discard ${backpackslot1}
            \*set backpackslot1 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot2 != "Empty")
      #${backpackslot2}
        You open up your pack to grab your ${backpackslot2}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot2 = "Meal")
            #Eat ${backpackslot2}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot2 "Empty"
                \*goto display
          #Discard ${backpackslot2}
            \*set backpackslot2 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot3 != "Empty")
      #${backpackslot3}
        You open up your pack to grab your ${backpackslot3}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot3 = "Meal")
            #Eat ${backpackslot3}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot3 "Empty"
                \*goto display
          #Discard ${backpackslot3}
            \*set backpackslot3 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot4 != "Empty") and (age >= 11)
      #${backpackslot4}
        You open up your pack to grab your ${backpackslot4}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot4 = "Meal")
            #Eat ${backpackslot4}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot4 "Empty"
                \*goto display
          #Discard ${backpackslot4}
            \*set backpackslot4 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot5 != "Empty") and (age >= 11)
      #${backpackslot5}
        You open up your pack to grab your ${backpackslot5}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot5 = "Meal")
            #Eat ${backpackslot5}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot5 "Empty"
                \*goto display
          #Discard ${backpackslot5}
            \*set backpackslot5 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot6 != "Empty") and (age >= 11)
      #${backpackslot6}
        You open up your pack to grab your ${backpackslot6}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot6 = "Meal")
            #Eat ${backpackslot6}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot6 "Empty"
                \*goto display
          #Discard ${backpackslot6}
            \*set backpackslot6 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot7 != "Empty") and (age >= 11)
      #${backpackslot7}
        You open up your pack to grab your ${backpackslot7}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot7 = "Meal")
            #Eat ${backpackslot7}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot7 "Empty"
                \*goto display
          #Discard ${backpackslot7}
            \*set backpackslot7 "Empty"
            \*goto display
          #Back
            \*goto display
    \*if (backpackslot8 != "Empty") and (age >= 11)
      #${backpackslot8}
        You open up your pack to grab your ${backpackslot8}...
        
        Now the question is what to do with it?
        \*fake_choice
          \*if (backpackslot8 = "Meal")
            #Eat ${backpackslot8}
              \*if (hunger = 0)
                Your not hungry!
                \*goto display
              \*if (hunger >= 1)
                \*set hunger - 1
                \*set backpackslot8 "Empty"
                \*goto display
          #Discard ${backpackslot8}
            \*set backpackslot8 "Empty"
            \*goto display
          #Back
            \*goto display

@2Ton
it looks very nice, thank you very much =) I might use it, or rather some of it =)
Very much appreciated =)

@dinosw yah there is some stuff you will need to edit but it should be decent enough.

@FairyGodFeather @Caddmuss @dinosw

Sorry I didn’t have time to back up that up with an example, if I’m not to late, I was thinking something like this:


*temp gold 1
*temp silver 1523
*temp bronze 10

*set silver (silver + (bronze / 100))
*set bronze (bronze % 100)
*set gold (gold + (silver / 100))
*set silver (silver % 100)

You have: ${gold} gold, ${silver} silver, ${bronze} bronze

I just threw that together quickly, but it should be right.
Assuming that 100 bronze is 1 silver and 100 silver is 1 gold.

@CJW

Not sure I understand that code, but if it works, it is much shorter than the roundabout I wrote.

I’ll look at it with fresh eyes tomorrow, it is almost 1 in the night here.

If you scroll up, I have my code in an earlier comment.
in the code, just look for:
*label wealth_regulater
*label converter_1
*label converter_2

Thank you very much for the input, it is really a great place for help =)

@dinosw

That code is actually wrong, I must’ve copied and pasted the wrong one (I had several iterations going), this is the right code:


*temp gold 1
*temp silver 1523
*temp bronze 112

*set silver (silver + ((bronze - (bronze modulo 100)) / 100))
*set gold (gold + ((silver - (silver modulo 100)) / 100))
*set silver (silver modulo 100)
*set bronze (bronze modulo 100)

You have: ${gold} gold, ${silver} silver, ${bronze} bronze

You probably don’t really need to understand it, but those *set four lines will basically convert any excess bronze coins (over 99) into silvers, and excess silvers into gold.
The other lines are just variable definitions and a quick display, for example purposes.

In that example it’ll turn:

Gold: 1
Silver: 1523
Bronze: 112

into

Gold: 16
Silver: 24
Bronze: 12

Copy and paste all that into here, if you want to see it working.

You basically just slap those four lines in anytime you want to sort ‘top-heavy’ currencies.

1 Like

I’ll certainly give it a go =) thank you @CJW