For this example, here’s what you’ll need to put into startup.txt;
*create money 5000
*create empty_inventory true
*create sword false
*create sword_name "Chainsaw-Sword of Brutalizing"
*create sword_dura 99
*create cape false
*create color ""
*create material ""
*create health_potion false
*create hp_number 0
This is what you put into choicescript_stats.txt;
*temp inventory ""
*temp comma false
*if (empty_inventory)
*set comma true
*set inventory &"You are carrying nothing"
*if (sword)
*set comma true
*set inventory &"$!{sword_name} (Durabillity: ${sword_dura})"
*if (cape)
*if comma
*set inventory &", "
*set comma true
*set inventory &"A $!{color} $!{material} Cape"
*if (health_potion)
*if comma
*set inventory &", "
*set comma true
*set inventory &"Health Potion(s) (x${hp_number})"
Inventory: ${inventory}
*line_break
Money: $${money}
What’s worth noting here is that the first item in the list doesn’t neccesarily need to insert a comma since it comes first, but since the code goes through it from top to bottom, there won’t be any problems either way. For advanced users, it is recommended to create a gosub to check whether or not the inventory is empty or not as this will save you a lot of trouble in the long run. This kind of list can be used for many other things as well, companions for example. The same principles could also be arranged into a more segmented inventory with slots for the head, torso etc.
And this is what you put somewhere in the game;
*label shop
*temp buy_price_s 800
*temp sales_price_s 0
*temp sales_price_s2 0
*temp sales_price_hp 0
*temp buy_price_hp 100
*temp buy_hp 0
Hello and welcome to Generic Dan's shop!
*label top
*set sales_price_s round((buy_price_s /2) +sword_dura)
What can I help you with today?
*line_break
Money: $${money}
*choice
*hide_reuse #Good morning sir, that's a very nice smile you got there!
*set buy_price_s -200
*set buy_price_hp -50
Listen you, I'll give you a discount if you promise to never say something so creepy ever again.
*page_break
*goto top
*if (sword = false)
*selectable_if (money >= buy_price_s) #I'd like to buy the new Chainsaw-Sword 5000! [i]($${buy_price_s})[/i]
*set empty_inventory false
*set sword true
*set money -buy_price_s
*if (money < 0)
*set money 0
Thank you kindly, here's your new Chainsaw-Sword 5000!
*page_break
*goto top
*if (sword)
#I'd like to sell my $!{sword_name}. [i]($${sales_price_s})[/i]
*set sword false
*if not ((cape) or (health_potion))
*set empty_inventory true
*set money +sales_price_s
Thank you kindly, I'll be taking your $!{sword_name} then.
*page_break
*goto top
*if (sword)
#(Bang the Chainsaw-Sword on the counter)
*set sword_dura %-10
Hey what are you doing, you bozo?! Stop that!
*page_break
*goto top
#I'd like to buy some Health Potions. [i]($${buy_price_hp} x1)[/i]
How many would you like?
*input_number buy_hp 0 99
*set sales_price_hp (100 * buy_hp)
So you would like to buy ${buy_hp} Health Potions? That'll be $${sales_price_hp} then.
*choice
*selectable_if (money >= sales_price_hp) #Yep. Here you go.
*set money -sales_price_hp
*if (money < 0)
*set money 0
*set empty_inventory false
*set health_potion true
*set hp_number buy_hp
A pleasure doing business with you!
*page_break
*goto top
#I can't afford that.
That's too bad, see anything else you like?
*page_break
*goto top
*hide_reuse *if (cape = false) #Are those Bat-Boy capes?
Yep, promotional item. We're giving them out free for the kids. Why, you want one? What color would you like?
*fake_choice
#Black
*label always_black
*set color "black"
#Black...
*set color "black"
#Black!
*goto always_black
#Pink!
*set color "pink"
*set material "polyester"
*set cape true
*set empty_inventory false
Here ya go...
*page_break
*goto top
*if (hp_number > 0) #(Drink a Health Potion)
*set hp_number -1
*if (hp_number = 0)
*set health_potion false
You chug down a cool refreshing health potion.
*page_break
*goto top
#I'm done shopping.
Okay, you come back again ya hear now? Have a nice day!
*page_break
*goto end
*label end
You walked out and immidiately got arrested.
So this is the shop. You can buy and sell, get a discount, get some free stuff and walk out. All with a nice and easily grasped user interface.
Everything here worked on the IDE Test page. The “bang your sword on the counter” option is only there to demonstrate an example on how the resale value will decrease the more damage is done to the weapon. As usual, I used a triple spacebar indent. See my Tutorial about genders for further information on indentation. As always, I’m happy to answer questions and take requests, but the easiest way to see what the code does is to copy paste it and see for yourself. Good luck!
https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/IDE/main.html#
My tutorials and many others can also be found at http://www.choiceofbox.com by @Lordirish