money(Gil) & item help

Started by Icey, Sat 03/07/2010 19:51:51

Previous topic - Next topic

Icey

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

   
Code: ags

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.


Ryan Timothy B

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:
Code: ags

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.

Calin Leafshade

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

Code: ags

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.


Code: ags


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.

NsMn


barefoot

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-
I May Not Be Perfect but I Have A Big Heart ..

Charity

"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.

Icey

yep. but i fixed it , thanks Calin

SMF spam blocked by CleanTalk