Creating multiple 'examine' messages for one hotspot.

Started by DJ_Gora, Sat 25/02/2017 12:43:48

Previous topic - Next topic

DJ_Gora

Hi.
I'm wanting to make it so if you keep using 'look' or a similar mouse mode on a hotspot or character, the message displayed changes each time.
So like if you keep looking at a mundane item, the narrator can gradually get more and more fed up with each reply, then eventually stop at one 'end' message that persists for the rest of the game. (Like an example is if looking at a door, it'll just say "It's a door" constantly after exhausting all the other mesages)
I'm sure it can be done in AGS as I've seen other games do it (Five Days a Stranger etc), but I can't figure out how to do it myself.
Does anyone have an idea on how to get it to work?

Cheer in advance.
You crack me up, little buddy.

NicolaGs

I think you could create a variable who stores the number of times you looked at the hotspot. Each time you look at it, you increase this number and you create a condition who check this number and acts differntly depending on this value.

Raw example:

Code: ags
int hotspot_looked = 0

..

function hHOTSPOT_Look()
{
	if (hotspot_looked == 0)
	{
		player.Say("first time dialog");
		hotspot_looked = hotspot_looked + 1;
	}
	else if (hotspot_looked == 1)
	{
		player.Say("second time dialog");
		hotspot_looked = hotspot_looked + 1;
	}
	...
	else if (hotspot_looked == 10)
	{
		player.Say("last time dialog");
	}
}


The variable could also be replaced with a custom property for the hotspot that you change each time :
hHOTSPOT.GetProperty("hotspot_looked") to retrieve the value
hHOTSPOT.SetProperty("hotspot_looked", NEW VALUE) to set the new value

Hope this helps you...

edit : corrections in the code following Crimson Wizard's remarks...
My first game : I Want Out!

Crimson Wizard

#2
Just do not repeat "hotspot_looked = hotspot_looked + 1;" under every condition, put it once in the end of the function, and optionally reset number if you want them to start anew.

Code: ags

function hHOTSPOT_Look()
{
   <... All the code ...>

   // if you want them to repeat from the start again -
   hotspot_looked++; // increase by 1
   if (hotspot_looked > 10)
       hotspot_looked = 0; // reset
   // if you do not want them to restart
   if (hotspot_looked < 10)
      hotspot_looked++; // increase by 1
}


Another note: setting property only works for AGS 3.4.0 and higher, so if you are using older versions you'd have to stick to variable.

DJ_Gora

Quote from: NicolaGs on Sat 25/02/2017 13:01:04
I think you could create a variable who stores the number of times you looked at the hotspot. Each time you look at it, you increase this number and you create a condition who check this number and acts differntly depending on this value.

Raw example:

Code: ags
int hotspot_looked = 0

..

function hHOTSPOT_Look()
{
	if (hotspot_looked == 0)
	{
		player.Say("first time dialog");
		hotspot_looked = hotspot_looked + 1;
	}
	if (hotspot_looked == 1)
	{
		player.Say("second time dialog");
		hotspot_looked = hotspot_looked + 1;
	}
	...
	if (hotspot_looked == 10)
	{
		player.Say("last time dialog");
	}
}


The variable could also be replaced with a custom property for the hotspot that you change each time :
hHOTSPOT.GetProperty("hotspot_looked") to retrieve the value
hHOTSPOT.SetProperty("hotspot_looked", NEW VALUE) to set the new value

Hope this helps you...

Thank you.
I've given this a try in my current project, however all the comments are played one after another in one go for some reason.
I think I'm doing something wrong.
You crack me up, little buddy.

Crimson Wizard

Change second and every following "if" to "else if".
(Last "if" could be changed to just "else")

Also, I recommend moving "hotspot_looked = hotspot_looked + 1;" line to the very end of the function, as I showed in example in my reply (see above).

NicolaGs

Quote from: DJ_Gora on Sat 25/02/2017 13:28:50
however all the comments are played one after another in one go for some reason.
I think I'm doing something wrong.
Of course, I did it too quickly. The fact that I incremented the variable in each If statement is dumb since each time the value is incremented and so the following condition is always true... Crimson Wizard gave you the right advice.

I edited my previous post.
My first game : I Want Out!

DJ_Gora

I got it working, Crimson Wizards modifications helped.
Now my character and the narrator can have witty banter until the cows come home.

Thanks a lot for the help, guys!
You crack me up, little buddy.

Cassiebsg

Just a quicky footnote...
I've recently started using Game.DoOnceOnly... so you could spare a variable there...

Code: ags

function hHOTSPOT_Look()
{
        if (Game.DoOnceOnly("1st time look at hotspot")
        {
                player.Say("first time dialog");
        }
        else if (Game.DoOnceOnly("2nd time look at hotspot")
        {
                player.Say("second time dialog");
        }
        ...
        else // Last time you only need a else 
        {
                player.Say("last time dialog");
        }
}


Since Game.DoOnceOnly only fires up once in game, it will automatically turn that If/if else into false, after it was run the first time. ;)
There are those who believe that life here began out there...

Lewis

Cassiebsg's way is probably neater if you want to avoid having a huge list of variables - though definitely make sure you have a unique name for each Game.DoOnceOnly, for example:

Code: ags
function hTable_Look()
{
        if (Game.DoOnceOnly("Room3_hTable_Look1")
        {
                player.Say("first time dialog");
        }
        else if (Game.DoOnceOnly("Room3_hTable_Look2")
        {
                player.Say("second time dialog");
        }
        ...
        else // Last time you only need a else 
        {
                player.Say("last time dialog");
        }
}
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

SMF spam blocked by CleanTalk