Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 07/06/2012 14:02:12

Title: Globalscript.asc-Items and Objects[SOLVED, for now...]
Post by: on Thu 07/06/2012 14:02:12
I have this code in Globalscript.asc for my inventory item...

Code (AGS) Select
function iDollari_OtherClick()
{
  // LOOK AT
  if(UsedAction(eGA_LookAt)) {
    player.Say("Il Barnett College mi paga molto bene!.");
  }
  // USE
  else if(UsedAction(eGA_Use)) {
    player.Say("Non in questo momento.");
  }
  // Push
  else if(UsedAction(eGA_Push)) {
    Unhandled();
  }
  // Pull
  else if(UsedAction(eGA_Pull)) {
    Unhandled();
  }
  //USE INV
  else if(UsedAction(eGA_UseInv)) {
    Unhandled();
  }
  else Unhandled();
}


Now, for some obscure reasons there is no interaction at all both player with GUI and items and items with hotspots...
While the basic items I've found in the demo still work of course. The code is identical, at least I think so...
Title: Re: Globalscript.asc-Items and Objects
Post by: Khris on Thu 07/06/2012 14:10:54
I've mentioned this a couple of times in your threads: with inventory items, you're actually supposed to use the different cursor mode events, not "any click on".
However, the reason why all interactions of the demo's inv items are handled within a single function, for instance "iCup_OtherClick", is that this name was pasted into all the event link fields. Open the demo's iCup's event page (thunderbolt icon) and compare it to your iDollari's.

Also, to handle what happens when item X is used on hotspot Y, you need to go to the hotspot's "any click on" event and in the function, use:
Code (ags) Select
  ...
  else if (UsedAction(eGA_UseInv)) {
    if (player.ActiveInventory == iDollari) {
      ...
    }
    else Unhandled();
  }
  ...


Please make sure you read and understand the manual PDF that comes with the template! It's right there in your game folder.
Title: Re: Globalscript.asc-Items and Objects
Post by: on Thu 07/06/2012 14:25:55
Damn, thanks for the fast answer as usual and sorry, I knew it but forgot to check the flash icon for the items!
Title: Re: Globalscript.asc-Items and Objects[Solved?]
Post by: Gabarts on Sat 09/06/2012 14:20:32
Hello again, as you can see I've changed my account :)

I have completed my first room and all is working fine but 2 objects...

I've checked again and again what is wrong but unfortunately they are not working like I want. Code seems right because AGS doesn't give me errors but maybe there is some link problem that I cannot find. Basically I'm using 2 objects visibility to show a closed and an opened wardrobe (with GUI interact for both). Here the code:

Code (AGS) Select
function casaperto_AnyClick()
{
    if (MovePlayer(340, 117)) {
     player.FaceDirection(eDir_Up);
 
  // LOOK AT
    if(UsedAction(eGA_LookAt)) {
      player.Say("Ora il cassetto è aperto.");
      Wait(5);
      player.Say("Phuaa!... che puzza!");
    }
  }
    // USE
    else if(UsedAction(eGA_Use)) {
      Unhandled();
    }
    // OPEN
    else if(UsedAction(eGA_Open)) {
      Unhandled();
    }
      // CLOSE
    else if(UsedAction(eGA_Close)) {
      oCasaperto.Visible = false;
      oCaschiuso.Visible = true;
    }
    // Push
    else if(UsedAction(eGA_Push)) {
      Unhandled();
    }
    // Pull
    else if(UsedAction(eGA_Pull)) {
      Unhandled();
    } 
    // PICKUP
    else if(UsedAction(eGA_PickUp)) {
      Unhandled();
    }
    //USE INV
    else if(UsedAction(eGA_UseInv)) {
      Unhandled();
    }
    // don't forget this
    else Unhandled();
}
     
function caschiuso_AnyClick() {

    if (MovePlayer(340, 117)) {
     player.FaceDirection(eDir_Up);
 
  // LOOK AT
    if(UsedAction(eGA_LookAt)) {
      player.Say("E' il cassetto della biancheria di mio padre.");
      }
    }
    // USE
    else if(UsedAction(eGA_Use)) {
      Unhandled();
    }
    // OPEN
    else if(UsedAction(eGA_Open)) {
     oCaschiuso.Visible = false;
     oCasaperto.Visible = true;
    }
      // CLOSE
    else if(UsedAction(eGA_Close)) {
      player.Say("E' già chiuso.");
    }
    // Push
    else if(UsedAction(eGA_Push)) {
      Unhandled();
    }
    // Pull
    else if(UsedAction(eGA_Pull)) {
      player.Say("Si apre normalmente, non c'è bisogno di tirarlo.");
    } 
    // PICKUP
    else if(UsedAction(eGA_PickUp)) {
      Unhandled();
    }
    //USE INV
    else if(UsedAction(eGA_UseInv)) {
      Unhandled();
    }
    // don't forget this
    else Unhandled();
}


The result is that the only action with GUI that is working is OPEN but doesn't switch to the other object. I've first tried with 1 hotspot and 1 object and the switch was working, but not the GUI. Where I am wrong?
Title: Re: Globalscript.asc-Items and Objects[SOLVED, for now...]
Post by: Khris on Sat 09/06/2012 14:37:28
You messed up the brackets, and since you don't use proper indentation either, you didn't notice.
In both functions, the else ifs for the other verbs are only checked if the player doesn't move to the closet, not if the action isn't "look".

If you had used proper indentation, you'd have immediately noticed this.

Here's the first part, unchanged, but indented according to the (wrongly placed) brackets:
Code (ags) Select
function casaperto_AnyClick()
{
  if (MovePlayer(340, 117)) {
    player.FaceDirection(eDir_Up);

    // LOOK AT
    if(UsedAction(eGA_LookAt)) {
      player.Say("Ora il cassetto è aperto.");
      Wait(5);
      player.Say("Phuaa!... che puzza!");
    }
  }
  // USE
  else if(UsedAction(eGA_Use)) {
      Unhandled();
  }


The } in line 12 needs to go way down, after the other verb blocks (which are supposed to be indented twice, or by four spaces).

Here's the corrected (& shortened) function:
Code (ags) Select
function casaperto_AnyClick()
{
  if (MovePlayer(340, 117) == 2) {
    player.FaceDirection(eDir_Up);

    // LOOK AT
    if (UsedAction(eGA_LookAt)) {
      player.Say("Ora il cassetto è aperto.");
      Wait(5);
      player.Say("Phuaa!... che puzza!");
    }

    // CLOSE
    else if (UsedAction(eGA_Close)) {
      oCasaperto.Visible = false;
      oCaschiuso.Visible = true;
    }

    else Unhandled();
  }
  else player.Say("I can't get there.");
}

Btw, you can set the default verb for the open closet to "close" by appending ">c" to the Description. So if the open closet is called "cassetto", change that to "cassetto>c" and if you move the mouse over it, the close verb will light up and is executed if you right-click it.
Title: Re: Globalscript.asc-Items and Objects[SOLVED, for now...]
Post by: Gabarts on Sat 09/06/2012 15:15:11
Thank you very much for the infos, now it works