Jump to content
Sign in to follow this  
koalasalad

money specific to each player

Recommended Posts

I do not really know how to explain what I'm trying to do but I will do my best. I created a working money system but my problem is that the money is shared between everyone. How would I make it so each player (there will only be 2 players) has their own money?

In this example money = 0

if (money < 100) then
{
   player1 groupChat format ["You cannot afford this item. You only have $%1", (money)];
} else {
   money = money - 100;
   player1 addWeapon "M9";
   player1 groupChat format ["You bought a M9 and have $%1 remaining", (money)];
};

The problem with this is that when the money is subtracted, it is subtracted from everyone. I need player1 and player2 to have their own money.

Would I have to do something like:

player1money = 0;
player2money = 0;

It would be nice if i could just do:

if (player1 money < 100) then...

Thanks for the help,

Koalasalad

Share this post


Link to post
Share on other sites

you could:

objectName [url="http://community.bistudio.com/wiki/setVariable"]setVariable[/url] [name, value (, public)]

and

object [url="http://community.bistudio.com/wiki/getVariable"]getVariable[/url] [name, defaultValue]

that way the value will stay specific to the unit...

The reason that "money" is shared is because it is named as a global variable (no underscore "_money")

more info on variables scope here

Edited by gammadust

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×