money

darkgoddessnight
06 Oct 2006, 18:51
I am trying to develop a system of currency, but I don't know where to start.
The general system that I want to apply is:
platinum = 10 gold
gold = 10 silver
silver = 10 steel
steel = 10 bronze
bronze = 10 copper
copper

but I am not sure exactly how to explain to my barkeeper that i want to buy a 3 copper beer with my gold peice and get my correct amount of change back.

any math wizzes out there who could help me?

GameBoy
07 Oct 2006, 05:20
You should probably start basic at first, using a single currency.

You could also use a collection of if statements. For example, if you have a command such as Buy beer from bartender you could use the following command after (or something similar) to check what you gave.

	command <give %ammount% #currency# to bartender> {
if ( #currency# = copper ) then dec <copper; 10>
if ( #currency# = bronze ) then dec <bronze; 1>
}


This checks what you typed as a currency, and it will decrease the currency by the correct ammount, and then you can add the rest of the script to calculate the change needed to be given using what the player entered into the %ammount% variable.

If you gave the bartender 1 gold, and it only cost them 5 copper, then you'd just give back 5 copper, and give the rest back in silver peices to make the remaining ammount.

But seriously, keep it simple to begin with, you can always extend it later.

paul_one
07 Oct 2006, 08:30
This will be SOOO much easier with Quest 4 - using the select cases.

I'll experiment with some code, and see if I can produce something..

darkgoddessnight
07 Oct 2006, 12:59
Thankyou so much :) can you tell I am a newbie?

GameBoy
07 Oct 2006, 16:57
Tr0n wrote:This will be SOOO much easier with Quest 4 - using the select cases.

I'll experiment with some code, and see if I can produce something..


Exactly what I was thinking lol

Elexxorine
08 Oct 2006, 16:00
you could have all money in copper form, but then have it display in the seperate forms, by dividing by 10 each time...

paul_one
08 Oct 2006, 19:26
BEWARE!!!

The following demo contains good code :P .
Read at the risk of your head exploding.

http://www.compwhizz.freeserve.co.uk/asldemos/money.asl

I've written it like this mainly because you can put it into a library with reletively minor changes.

To get it working in multiplayer will be a b1-0tch though, as this has a nasty hack to work around some of the ways Quest works.. And is almost impossible to look at when coded for multiplayer.
I don't even think it's really possible..

The harder parts are because of the status variables, and Quest's use of default global variables (which means you can't build recursive functions properly..). The global variable issue slowed me down quite a bit.

Anyway, on the example, it has 5 different types:
black, dark grey, grey, light grey, white (like your gold, silver, bronze, etc).
This you can add to or remove, without having to change anything but the starting array, variables used, and possibly the [game] object properties (which is alot easier than going around altering code all the time).

It detects if you don't have enough coins for such a situation, it allows you to either use a built-in returning string (saying what the coins have changed to - or if it's not allowed) or you can specify your own (I have two commands - one uses in-built, the other doesn't).

The only gripe is multiplayer... See if Elex can understand it and try to get it working in multiplayer.

:EDIT:

You can set the numeric variables up at the start, by simply running "$chngprops(game;backup)$" which will set-up the variables and mean you don't NEED to set them up... Except you really only want them if they're status var's - so you do :D ..
I guess you could remove all the status var's!

... I'll see if I can try multiplayer stuff.

Elexxorine
09 Oct 2006, 16:25
I've glanced over it... ouch. That's all I can say. If I have a bit of spare time I'll look it in much greater detail and work on the multiness...

Tron, are you saying that I'm better at coding for multiplayer than you? Does this mean I'm up there with you and the other coding legends? Neat.

paul_one
09 Oct 2006, 20:11
You're better than me at multiplayer coding.
You might also know a couple of quirks I don't, seeing as how it's multiplayer.

Elexxorine
09 Oct 2006, 20:27
Hey thanks man. Still can't believe I'm the one to come to in need of multiplayer help... I haven't been coding for that long... But yeah, I have tried to get good at the multiplayer stuff, some of the stuff in HavenHold scares even myself, but that money code! *code flies over head* Nice.

GameBoy
09 Oct 2006, 22:06
Good work Tr0n

I think Im Dead
13 Oct 2006, 05:05
Seems like the whole money issue for multiplayer would work quite easily if you were to be a bit more subjective about it. It's all basically different (and conveniently rounded) multipliers for one standard unit of currency.

Instead of using variables to store equated values, have a master list of currency multipliers, ie: platinum=1000; gold=100; silver=10; copper=1, then simply take a total of x, test it by a,b,c and/or d then output the results.

The only really "hard" part would be parsing things out, but that's more finesse really.

paul_one
13 Oct 2006, 20:47
>.< dammit...

Stupid straight forward answers!

... I'd have to second that way of doing things.. So much better, more simple, etc.

darkgoddessnight
13 Oct 2006, 22:03
*waits paitiently for someone to post a multiplayer code for money*