How to script money system

Started by Zephyr, Sat 09/11/2019 14:10:25

Previous topic - Next topic

Zephyr

Hi again, Everyone,

                           I've come to a point in my game where I want to have a working money system - finding and spending varying amounts of cash. Now, I know this question has been asked before (Khris answered a similar question from Shavit back in October 2013), and I followed those instructions to the letter (although I have to confess I didn't really have the faintest idea of what each line meant!), but I was getting error messages such as "undefined token money", etc.  Once again I've managed to get myself as confused as hell and I don't know if it's something that I've done (or NOT done), or if the problem is that the instructions that I followed from 2013 are now obsolete.

At the moment I have my character finding a moneybag (oMoneybag) which on interaction disappears and becomes an inventory item (iMoney), which on the Look command displays the amount of £30.  Later he finds another £5 and so on. I'm also going to make several shops where, of course, the total amount will change again.

Any geniuses out there who could help me out please?  Please note - you'll need to dumb down your replies for me I'm afraid!

-  Zephyr

???  (wtf)  :-[
<3 Zephyr <3

Jack

#1
Quote from: Zephyr on Sat 09/11/2019 14:10:25
At the moment I have my character finding a moneybag (oMoneybag) which on interaction disappears and becomes an inventory item (iMoney), which on the Look command displays the amount of £30.  Later he finds another £5 and so on.

This is fine, doesn't need to be much more complex than this. All you need additionally is an int (Integer) variable to keep track of how much money the player has. Define it as a global variable for simplicity's sake, and increase it by 30 when he finds the £30. You check if they have enough when they want to buy and decrease it when they have bought something.

Another way is to use the inventory system, this may be even simpler. You can define how many of each inventory item a player has, and use this number (also an int) to represent the amount of iMoney.

Zephyr

Hi Jack,

          Thank you for replying so soon. What you're advising sounds fairly simple... but when I say "dumb down", I mean REALLY dumb down! (I'm so sorry, I get so confused with Global Scripting for some reason!)

Can you give me a clue as to just how to word it please? And would this automatically keep a tally of changes to money throughout the game?

-  Zephyr
:undecided: :confused: :embarrassed:
<3 Zephyr <3

Slasher

#3
Here is one quick way..

Open the Global variables node in the editor.

Right click in white area to add new variable.

Choose type: int.

Give it a name... Money

Set a start value..

Money is now a variable that can be manipulated in script.

To add say 5

you would add at the appropriate place(s) in you scripts

Code: ags

Money +=5;   //  Or Money -=5;  to take it away


To visually show how much you have you could make a label on a gui and name it LMoney. (The amount of money you have can be shown in various ways).
In the Global ash script in this function add

Code: ags

function repeatedly_execute_always() 
{
    LMoney.Text=String.Format("%d",Money); // the label will now show how much money you have at any one time

}






Zephyr

Hi Slasher,

               Man,you're my hero!  I did everything you said and it's working perfectly!  When I read complex replies, my poor brain just turns to mush, but your instructions were so simply put that I had little trouble following you.

Thank you so much for your help!

- Zephyr
:-D  :-*
<3 Zephyr <3

SMF spam blocked by CleanTalk