[SOLVED] Interact with hotspot AFTER running a DoOnceOnly talk to hotspot?

Started by rickious, Tue 17/09/2013 08:05:44

Previous topic - Next topic

rickious

Im sure the answer is online for this but after a day and a half of trying to word it right on here, the help file, and Google I give up and will ask the experts (you) :-D

So, the character talks to a hotspot for a one off event.  Basically asking someone to open a door. Then I want the player to be able to interact with the door to exit the room.
Code: ags

function hHotspot2_Talk()

{
  if (Game.DoOnceOnly("Talk to door1"))
  {
    cEgo.Say("Can you open this door for me... Please.");
    Wait(30)
    adoor3.Play();
  }
   Display("The door now unlocked");
}


So, you talk to the door. Character says "can you open this door for me... Please".  Then sound 'adoor3' (sound of door unlocking) plays after a short pause for the on screen dialogue.  The final 'Display' is simply so there is still a reaction if you try to talk to the door again (as the game crashed if I tried talking to the hotspot again so I added this until I figure that out.).

QUESTION 1 How do I now make the door hotspot 'Interact' enabled as a result of the above.

QUESTION 2 How do I make a new reaction to the player talking to this hotspot which will only run all future times and NOT this time.  At the moment with my basic code, the final 'Display("The door now unlocked");' runs at the end of the initial 'talk' and all future ones. So I want a separate initial reaction and all future reactions.

QUESTION 3 How can I close the 'talk' option at the end of this 'DoOnceOnly' event so nothing happens (for future reference.)

Thanks in advance as Im sure this is easy enough for seasoned scripters to answer.
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Stupot

For question 2, if you were to put  Display("The door now unlocked");  before the closing bracket of DoOnceOnly, it should display The door is now unlocked only the first time.  Then have   else{Display("Something else");}  so the 'something else' should only be displayed when it is not the first time.
Code: ags

function hHotspot2_Talk() 
{
  if (Game.DoOnceOnly("Talk to door1"))
  {
    cEgo.Say("Can you open this door for me... Please.");
    Wait(30)
    adoor3.Play();
    Display("The door now unlocked");
  }
  else
  {
    Display("Something else");
  }
}


Now, I think if you deleted  else{Display("Something else");}   that should solve question 3, but I don't know why it was crashing before.
MAGGIES 2024
Voting is over  |  Play the games

Khris

Regarding Q1:
Code: ags
  hDoor.Enabled = true;

(It's good practice to rename hotspots from hHotspotX to a proper name starting with "h" before creating any functions. You can do that in the hotspot's properties.)

Q3: I'd consider it bad game design to disable a "dead" hotspot, but removing any kind of reaction to clicking is even worse, IMO.
(The difference is that in the latter case, the hotspot still shows up if the game has an active cursor or an action line, etc.)
The best way is to do like Stupot suggested and tell the player that they're done with the hotspot.

Stupot

Quote from: Khris on Tue 17/09/2013 10:48:49
Regarding Q1:
Code: ags
  hDoor.Enabled = true;


But he needs it to be enabled in order to 'talk' to it, right?
I think he means he wants to enable the 'interact' function as a result of runing the 'talk' function. Is that right, Rickious?

If so, I'd have a variable (DoorUnlocked) and set it to false when the game starts.
Then when running the 'talk' function change DoorUnlocked to true.
In the 'Interact function' I'd have something like:
Code: ags
bool DoorUnlocked = false

function hHotspot2_Talk() 
{
  if (Game.DoOnceOnly("Talk to door1"))
  {
    cEgo.Say("Can you open this door for me... Please.");
    Wait(30)
    adoor3.Play();
    Display("The door now unlocked");
    DoorUnlocked = true;
  }
  else
  {
    Display("Something else");
  }
}


function hHotspot2_Interact()
{
  if (DoorUnlocked = true)
  {
    // Open door and go through it
  }
  else
  {
    cEgo.Say("The door is locked");
  }
}

'Interact' is always enabled, but it just gives you a different result depending on whether the door is unlocked or not.
MAGGIES 2024
Voting is over  |  Play the games

rickious

Thanks for the question replies and the tips.

Ill try that variable to change the interact for the door now

Ill get into the habit of renaming hotspots when I make them

I would be adding some kind of comment for trying to interact/talk etc to things that dont need you to yet/anymore/ever, I just wanted to get some solid work done on the basics for now, but probably best to do it as I go along.  Im still only in my first room, wanted to get my interact with the door done before moving out. 
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

rickious

QuoteI think he means he wants to enable the 'interact' function as a result of runing the 'talk' function. Is that right, Rickious?
Yes thats right. (laugh)

Made the changes and getting error...
Expected ',' or ';', not 'int' (referring to the line 'bool DoorUnlocked = false')

Looking into a fix now but if you know whats wrong please do say.  Ill post if I fix this before a reply.
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

rickious

right I put a ';' after the initial 'bool DoorUnlocked = false'

then I get...

Parse error in expr near 'DoorUnlocked' (At the 'if (DoorUnlocked = true)'
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Stupot

Quote from: rickious on Tue 17/09/2013 12:21:59
right I put a ';' after the initial 'bool DoorUnlocked = false'

then I get...

Parse error in expr near 'DoorUnlocked' (At the 'if (DoorUnlocked = true)'

Ahh, my bad.  Try 'if (DoorUnlocked == true)' with two equals signs.
MAGGIES 2024
Voting is over  |  Play the games

rickious

I changed it to..
Code: ags
  if (DoorUnlocked) cEgo.Say("TEST");
and it worked.  So at the moment it says its locked until you talk to the door then it now says "TEST", so ill model and render my next room and carry on.

Cheers.  Sure Ill see you in another noob help request thread (by me) soon. (roll)
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Stupot

Quote from: rickious on Tue 17/09/2013 12:41:38
I changed it to..
Code: ags
  if (DoorUnlocked) cEgo.Say("TEST");
and it worked. 
Yep. Or do that :-D
Good luck with the rest of the game :-)
MAGGIES 2024
Voting is over  |  Play the games

SMF spam blocked by CleanTalk