Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Sat 03/07/2010 19:51:51

Title: money(Gil) & item help
Post by: Icey on Sat 03/07/2010 19:51:51
I no I asked this before but how do i get the money system to work in my game cause i dont want the player to by something then when the seller say you dont have enough money to get this,u go in to your items box and somehow you got the item

   
Display("steam plans cid's:here's your steam plan, I need 10 gil.");

if(GiveScore(10)){     
GiveScore(-10);
cEgo.AddInventory(sp);
}
if(GiveScore(-10)){
Display("steam plans cid's:sorry kid, need more gil then that.");
}


also i want it to be were if you have 10 & up you can by this or else it makes it were you have to have a perfect 10 money to buy this.

Title: Re: money(Gil) & item help
Post by: Ryan Timothy B on Sat 03/07/2010 20:08:50
I've answered this in your in production thread, didn't know you started a thread in here.  Which is good, because you shouldn't ask tech questions in your production thread.

Here was the answer:

You're supposed to use game.score:

if (game.score>=10) {
  GiveScore(-10);
  cEgo.AddInventory(sp);
}
else
{
  Display("steam plans cid's:sorry kid, need more gil then that.");
}


GiveScore(int) sets the score.  To get the score you need to check the game variable.
Title: Re: money(Gil) & item help
Post by: Calin Leafshade on Sat 03/07/2010 20:17:35
Well you're almost there.

GiveScore is a command to *change* the score.. not find its value.. you need this:

right ok lets analyse this code and see how it works


Display("steam plans cid's:here's your steam plan, I need 10 gil.");

if(game.score >= 10){     // this line checks to see if game.score is larger than or equal to 10. if it is then it runs everything inside this first set of curly brackets.. the { signs
GiveScore(-10);            //  this line will add -10 to the score.. if you add a negative number its the same as taking it away.
cEgo.AddInventory(sp); //and then it adds the inventory item 'sp'
}                                      // end of the first set of brackets
else {                            // ok this line simply means "do this if the first 'if' wasnt true"
Display("steam plans cid's:sorry kid, need more gil then that.");
}


does that seem clear?

also you need to remember that if you do this again it will take 10 gil from you again and give you another copy of the plans... you can avoid it like this.




if (player.HasInventory(sp)) Display("Nahh I already have the steam plans.");
else if(game.score >= 10){    
   GiveScore(-10);            
   cEgo.AddInventory(sp);
}                                      
else Display("steam plans cid's:sorry kid, need more gil then that.");



this checks if you already have the plans first.. if you already have them you dont need to make any other checks.. which is was the 'else if' part is for.

'else if' means it will only check to see if its true if the previous check was false.

also do you see how i've neatened up the code? you dont need to use the curly brackets if there is only 1 command after the if statement.

I hope this helps.

EDIT: Beaten by ryan and his ninja ways.. but i'll be damned if i typed this shit for nothing.
Title: Re: money(Gil) & item help
Post by: NsMn on Sat 03/07/2010 20:29:11
Who is Gil?
Title: Re: money(Gil) & item help
Post by: barefoot on Sat 03/07/2010 22:30:04
Quote from: NsMn on Sat 03/07/2010 20:29:11
Who is Gil?

if you look its a currency/point system of some kind...

-barefoot-
Title: Re: money(Gil) & item help
Post by: Charity on Fri 09/07/2010 07:01:17
"Gil" is the name of the currency used in the Final Fantasy series of JRPGs.  I'm assuming Icey referenced it so people familiar with that series would know what sort of system he was aiming for.
Title: Re: money(Gil) & item help
Post by: Icey on Fri 09/07/2010 12:39:39
yep. but i fixed it , thanks Calin