Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sat 02/04/2005 12:49:30

Title: Scripting problem with dialog-based shop [SOLVED]
Post by: on Sat 02/04/2005 12:49:30
I'm trying to make a shop, where you talk to the salesman, and then buy something.
on a certain point were you click "yes", there starts a script, i did that with:

@1  // option 1
EGO: Yes
run-script 5

that links to:

// main global script file


  function dialog_request (int){
    if (GetGlobalInt(2) >= 15000) {
AddInventory (6);
SetGlobalInt (2, GetGlobalInt(2)-15000);
}
else {
   Display ("you don't have enough money");
   }

GlobalInt is my money, and when this script start, it checks if you have enough money. The problem is that even when you don't have enough money, you still get the item.
What am i doing wrong ???

EDIT:

DO NOT REPLY, I AM SO DUMB, I FORGOT THAT I FIRST TESTED THE ITEM, SO I MADE THE GAME START WITH THAT ITEM.....

THE SCRIPT I USED WORKS FINE, YOU CAN USE IT IN YOU GAME IF YOU WANT.
AND MODERATORS, DELETE THIS TOPIC!
 


Title: Re: Scripting problem with dialog-based shop
Post by: strazer on Sat 02/04/2005 15:32:58
The way your dialog_request function is set up now, ANY run-script command gives you the item if you have enough money since you don't check the parameter.
It should be


// main global script file

function dialog_request (int parameter) {

  if (parameter == 5) { // if function called via "run-script 5"
    if (GetGlobalInt(2) >= 15000) { // if player has enough money
      AddInventory (6); // give player inventory item 6
      SetGlobalInt (2, GetGlobalInt(2)-15000); // deduct cost from money
    }
    else { // if player doesn't have enough money
      Display ("you don't have enough money");
    }
  }
//else if (parameter == 78) { // if function called via "run-script 78"

}