Scripting help for Region interactions.

Started by HereComeDatBoi, Sun 28/12/2008 05:39:54

Previous topic - Next topic

HereComeDatBoi

In my story my charcter is supposed to walk on a specific part of the room and the a NPC will start talking I have worked out how to do this:

function region1_WalksOnto()
{
cGloriana.Say ("HELP, HELP!");
cGloriana.Say ("CAN SOMEONE PLEASE HELP!");
}

although I would like to know how I could make it so that once my character has stepped on this region once and the dialog has happened how I could make it so that this never happens again when I step on the region.

Gilbert

#1
Use variables.

On the top of the room's script:
Code: ags
int steppedonregion1=0;


Then change your region code to:
Code: ags
function region1_WalksOnto()
{
  if (steppedonregion1==0)[
    cGloriana.Say ("HELP, HELP!");
    cGloriana.Say ("CAN SOMEONE PLEASE HELP!");
    steppedonregion1=1;
  }
}

HereComeDatBoi

#2
Iv had a bit of a problem when I put this in the script. Because it doesn't recignise steppedonregion. What do you mean by put on top of room script ???

Gilbert

It is just a random name for a variable. I made a typo, that the variable was declared as steppedonregion1 (should be fixed now). Make sure the names match.

On top of the room script means that you just open the particular room's script and put the line there, before any function contents.

Nickydude

The idea behind it is that you're making a kind of switch, you can call this anything "steppedonregion1" or "hasplayertalked" or whatever you want to call it. Set it to zero right at the top of the room script, meaning the player hasn't 'steppedonregion1' or 'hasplayertalked' then do exactly as Gilbert says. When the function runs it checks to see if your variable is zero, it it is, the player will say the stuff then set the variable to 1. When the player steps in the region again, the function checks the variable, sees that it's 1 and skips the say stuff.

:)
Best Regards,
Nickydude
www.madladdesigns.co.uk

AGS Beginner's Guide - All you'll ever need!

Khris

Alternatively, you can use the quite new DoOnceOnly function:

Code: ags
function region1_WalksOnto() {
  if (Game.DoOnceOnly("glorianaasksforhelp")) {
    cGloriana.Say ("HELP, HELP!");
    cGloriana.Say ("CAN SOMEONE PLEASE HELP!");
  }
}

RickJ

Quote
What do you mean by put on top of room script..
As Gilbet said, this means to declare the variable outside the bounds of any function.  Most people put these kinds of variable declarations at the beginning of the script file before any functions are defined.  Variables defined in this way are called static variables and they retain their values throughout the game. They can be used in any function in the script file in which they are defined.   

Variables can also be declared within the bounds of a function and are called dynamic variables.   Variables defined in this way are called dynamic variables and do not retain their values only until the function, in which they are defined, completes it's execution.   They can only be used within the function in which they are defined. 

HereComeDatBoi

Ty every1 I used KhrisMUC's solution thanks of the help!! ;D

SMF spam blocked by CleanTalk