Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zeta_san on Tue 08/02/2022 08:58:14

Title: give
Post by: zeta_san on Tue 08/02/2022 08:58:14
Hi guys

I have a problem with the tumbleweed template

to enter the character must give a ticket at the entrance.

I can't do this thing.

I also read here
https://www.adventuregamestudio.co.uk/forums/index.php?topic=57962.0

but I don't get out of it
Title: Re: give
Post by: Khris on Tue 08/02/2022 10:46:56
It works for me when I do this:

Code (ags) Select
  // GIVE TO
  else if (Verbs.UsedAction(eGA_GiveTo)) {
    if (Verbs.GetItemGiven() == iKeyCard) cHologram.Say("Thanks!");
    else {
      player.Say("Do you want this?");
      cHologram.Say("I have no pockets.");
    }
  }


What have you tried? How did it fail? Etc?
Title: Re: give
Post by: zeta_san on Tue 08/02/2022 10:54:45
where do you enter the code?
Title: Re: give
Post by: Khris on Tue 08/02/2022 10:57:30
In the function handling the character's "any click" event.
Title: Re: give
Post by: zeta_san on Tue 08/02/2022 11:04:19
in global script?
Title: Re: give
Post by: Khris on Tue 08/02/2022 13:06:30
Yes, characters are global entities, so that is where AGS creates the function when you create the event link by clicking the [...] button.

I'm honestly a bit concerned by your asking these questions, how did you add other interactions so far?
Title: Re: give
Post by: zeta_san on Tue 08/02/2022 14:31:12
i resumed the project after a year and i feel insecure :cry:
Title: Re: give
Post by: Khris on Tue 08/02/2022 17:21:27
Oh no, sorry, I didn't mean to disturb you; I had no idea about that pause.

Quick recap:
Use the "any click" event for all interactions. Select an object, hotspot or character, click the âš¡ icon to switch from the properties to the events, select the "any click on..." event, then click the small [...] button that appears at the end of the text field next to the event name. Clicking the ellipses button will create the function and take you to it, so you don't have to worry about where to create it.

Inside the function, use the example code provided in the template to tell AGS how to react based on which verb was used.

You should also definitely take a look at the PDF that comes with the template; you can find it inside your game project folder.

Example code for a cup (room object):
Spoiler
Code (ags) Select
function cup_AnyClick() {
  // LOOK AT
  if (Verbs.UsedAction(eGA_LookAt)) {
    player.Say("It's a blue cup.");
  }
  // USE
  else if (Verbs.UsedAction(eGA_Use)) {
    player.Say("I'd rather pick it up.");
  }
  // PICKUP
  else if (Verbs.UsedAction(eGA_PickUp)) {
    player.Say("Okay.");
    Verbs.AnyClickWalkLookPick(108, 100, eDir_Up, "You are now mine.", oCup.ID, iCup);
  }
  //USE INV
  else if (Verbs.UsedAction(eGA_UseInv)) {
    Verbs.Unhandled();
  }
  // don't forget this
  else Verbs.Unhandled();
}
[close]
Title: Re: give
Post by: zeta_san on Tue 08/02/2022 17:46:49
Don't worry, you have not offended me, on the contrary it is a stimulus to grow.

I'm experimenting thanks for the info
Title: Re: give
Post by: zeta_san on Tue 08/02/2022 19:49:14
Quote from: Khris on Tue 08/02/2022 17:21:27
Oh no, sorry, I didn't mean to disturb you; I had no idea about that pause.

Quick recap:
Use the "any click" event for all interactions. Select an object, hotspot or character, click the âš¡ icon to switch from the properties to the events, select the "any click on..." event, then click the small [...] button that appears at the end of the text field next to the event name. Clicking the ellipses button will create the function and take you to it, so you don't have to worry about where to create it.

Inside the function, use the example code provided in the template to tell AGS how to react based on which verb was used.

You should also definitely take a look at the PDF that comes with the template; you can find it inside your game project folder.

Example code for a cup (room object):
Spoiler
Code (ags) Select
function cup_AnyClick() {
  // LOOK AT
  if (Verbs.UsedAction(eGA_LookAt)) {
    player.Say("It's a blue cup.");
  }
  // USE
  else if (Verbs.UsedAction(eGA_Use)) {
    player.Say("I'd rather pick it up.");
  }
  // PICKUP
  else if (Verbs.UsedAction(eGA_PickUp)) {
    player.Say("Okay.");
    Verbs.AnyClickWalkLookPick(108, 100, eDir_Up, "You are now mine.", oCup.ID, iCup);
  }
  //USE INV
  else if (Verbs.UsedAction(eGA_UseInv)) {
    Verbs.Unhandled();
  }
  // don't forget this
  else Verbs.Unhandled();
}
[close]




I have 6 tickets with different destinations.
I have activated 6 different hotspots that are activated if I give the associated ticket

how can they be put together?

Code (ags) Select




function cControllore_AnyClick() {

function cControllore_AnyClick() {

  // GIVE TO
  if (Verbs.UsedAction(eGA_GiveTo)) {

    if (Verbs.GetItemGiven() == iTicketxxx1)
      player.Say("Ecco il mio biglietto");
      cControllore.Say("Bene puoi andare!");
      cControllore.Say("Il treno per xxx1 sta per partire");
      player.LoseInventory(iTicketxxx1);
      Verbs.MovePlayer(155, 120);

   
    if (Verbs.GetItemGiven() == iTicketxxx2)
      player.Say("Ecco il mio biglietto");
      cControllore.Say("Bene puoi andare!");
      cControllore.Say("Il treno per xxx2 sta per partire");
      player.LoseInventory(iTicketxxx2);
      Verbs.MovePlayer(155, 120);


ecc

    } else {
      cControllore.Say("Non lo voglio");
    }

  }

  }
Title: Re: give
Post by: Khris on Wed 09/02/2022 09:50:21
First of all: you need to put these commands inside a {} block.

The bad way:
  if (...)
    CommandA();
    CommandB();

Here CommandB is always executed, only CommandA() is conditionally executed based on the test.

Here's the correct way:
Code (ags) Select
  if (...) { // opening curly brace
    DoSomething(); // conditional commands inside the block
    DoSomethingElse(); // more conditional commands
    DoEvenMoreStuff(); // more conditional commands
  } // closing curly brace


Secondly, I'm not seeing any lines related to hotspots.

Thirdly, are you asking how to shorten the code so you don't have six more or less identical blocks of code?
Title: Re: give
Post by: zeta_san on Wed 09/02/2022 11:00:49
it is theoretically .. the idea is not to create 6 rooms for train departure and 6 rooms for arrival

------

I enter the room
I speak to the stationmaster
tells me to buy the ticket
I go to the ticket office
      change of room
      there are 6 different destinations
      I buy a ticket
I give it to the stationmaster
                     change of room
                     arrival at destination


everything is managed by the iTicketxxx

Title: Re: give
Post by: Khris on Wed 09/02/2022 11:33:29
Right. There's no need to create six rooms for that. You can simply store the destination in a global variable.
Use a single room, a single ticket inv item, etc.

Create a global int called "destination" or something.
When you buy the ticket, after the user has picked the destination, use
Code (ags) Select
  destination = 1;
to store the choice. Whenever the choice is relevant, use the variable. For instance when looking at the ticket:
Code (ags) Select
function iTicket_OtherClick() {
  if (Verbs.UsedAction(eGA_LookAt)) {
    if (destination == 1) player.Say("It's a train ticket to Bologna.");
    else if (destination == 2) player.Say("It's a train ticket to Rome.");
  }
  else Verbs.Unhandled();
}

(code not optimized in any way)

You can also write a function that returns the name of the destination:
Code (ags) Select
String TrainDestination() {
  if (destination == 1) return "Bologna";
  if (destination == 2) return "Rome";
  ...
}


Now you can use that like:
Code (ags) Select
  player.Say("It's a train ticket to %s.", TrainDestination());
Title: Re: give
Post by: zeta_san on Wed 09/02/2022 12:25:21
not bad. thank you