How to get a different response from a hotspot after an event

Started by SeventhBard, Thu 19/08/2010 12:55:37

Previous topic - Next topic

SeventhBard

I apologize in advance at the newb-tacularness of this query.

Problem is, it's been a few years since I've worn the programmer hat, and I was never that advanced when I was wearing it. I can't seem to recall the correct language to ask for what I want to do beyond ("er I need an IF/THEN but uh, IF what THEN what?" doesn't go over well in the search engine ha ha) which has made looking up the answer myself more difficult than I first thought. I searched the tutorial, poked around these pages, played the demo game, and finally poked around the code in the demo game, but I am still a bit at a loss.

I'm making a two-room exploration game to try to learn the program and get a feel for the scripting. I've got a hotspot that is set to display some text when you talk to it. I've also got an object that you can pick up and use to interact with the hotspot. What I would like to do is set it so that AFTER you use the object on the hotspot, it from then on displays a different message upon being talked to. Can anyone point me where I should be looking for tips on how to code things like that?

Thanks much!

Matti

Just use a variable ("objectuse" in my example).

Pseudo-
Code: ags

bool objectuse=false;

// Click on hotspot:

if (objectuse==false) display stuff 1
else if (objectuse) display stuff 2

// Use object on hotspot:

objectuse=true;

Calin Leafshade

#2
it kinda depends on the condition.

If the condition is just a generic 'after some event' then you can just use a bool (true or false) variable.

like this
Code: ags

bool done;
function hHotspot_Look(){
  if (done) Display("If done is true say this");
  else Display("If done is NOT true say this");
}


if you have multiple actions from the if statement then you use brackets like this

Code: ags

if (done) {
     Display("Do this");
     Display("And this.");
}
else {
    Display("do this if it's not true");
    Display("and this");
}


See how i indented the lines in the brackets to make it easier to read?

now you need to consider something variable scope.

if the event you're checking for is in the same room then you can just declare your bool variable at the top of the room script *outside* all the functions.

if the event happens in a *different* room then the variable needs to be global so you can declare that in the Global Variables pane in the editor.

I hope that helps.

Edit: beaten by matti D:

to expand on matti's post.

Code: ags

if (objectuse==false) display stuff 1
else if (objectuse) display stuff 2


while this code would work 100% fine its not very tidy or efficient.

remember that a bool can *ONLY* be true or false and that the conditions can be written simply like this

Code: ags

if (objectuse) Display("whatever"); // This means if objectuse == true
else Display("or else"); // if its not true it HAS to be false.
if you need to see if its not true you can use

if (!objectuse)

the ! operator simply means 'not' and in this case could be written as objectuse == false



the more you know!

Dualnames

Code: ags

function Object0_Interact(){
object[0].Visible=false;
player.AddInventory(icandy)//or whatever have you
}
function hHotspot1_UseInv(){
if (player.ActiveInventory==icandy) { //if you clicked with the candy
Display("Yay, you got teh candy.");
//ideally you could also lose the candy
//player.LoseInventory(icandy); (it won't work)
}
else {//if you clicked with something else
Display("No money no funny bunny honey.");
}
}


if you want a different message after you;ve used the candy once. There  goes
Code: ags

bool usedcady=false;


function Object0_Interact(){
object[0].Visible=false;
player.AddInventory(icandy)//or whatever have you
}
function hHotspot1_TalkTo(){
if (usedcandy) Display ("Owned");
if (!usedcandy) Display ("You need candy.");
}

function hHotspot1_UseInv(){
if (player.ActiveInventory==icandy) { //if you clicked with the candy
Display("Yay, you got teh candy.");
//ideally you could also lose the candy
//player.LoseInventory(icandy); (it won't work)
usedcandy=true;
}
else {//if you clicked with something else
Display("No money no funny bunny honey.");
}



EDIT: WTF d00des!! ;)
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SeventhBard

Just wanted to offer my XTREME BELATED thanks for the help with the scripts! Can't believe I didn't post this earlier, I just noticed today when I went to have another look at your samples. Oy.

NickyNyce


SMF spam blocked by CleanTalk