Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Unknown_Terror on Tue 30/01/2007 21:07:03

Title: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 21:07:03
Hey guys, I need a bit of help getting this part of my script to work..
In my Dialog topic i want the character i'm talking to to go get an item for me after i ask him about it. In my Dialog Script i have added the line: run-script 1 and to the Global script i have used the following code to do it....


function dialog_request (int 1) {        \\Something is wrong with this line
character[BUT].ChangeView(1);            I get the Error "PE02: Parse Error
character[BUT].Walk(198, 142);                   at "1"  I'm guessing 1 is the
character[BUT].FaceLocation(199, 88);         wrong value for the run-script
character[BUT].ChangeRoom(6);                   value.
Wait(160);
character[BUT].ChangeRoom(2, 198, 142);
character[BUT].FaceLocation(197, 155);
character[BUT].Walk(224, 147);
character[BUT].ChangeView(7);
}

Any help is much appreicated, Thanks in advance
Title: Re: Dialog_Request script
Post by: GarageGothic on Tue 30/01/2007 21:11:24
What you need is this:

function dialog_request (int parameter)  {
  if (parameter == 1) {
    character[BUT].ChangeView(1);
    character[BUT].Walk(198, 142);
    character[BUT].FaceLocation(199, 88);
    character[BUT].ChangeRoom(6);         
    Wait(160);
    character[BUT].ChangeRoom(2, 198, 142);
    character[BUT].FaceLocation(197, 155);
    character[BUT].Walk(224, 147);
    character[BUT].ChangeView(7);
    }
  }


I haven't checked the entire code, but the function declaration was definitely wrong. Let me know if you get other problems further down.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 21:25:39
No it worked perfectly apart from the fact for forgot the word True at the end of the Walk co-ordinates.

I read through the manual on various topics and it didn't seem to explain it very well.

But i see now what i did wrong. I didn't realise i had to keep it as (int parameter) I thought i could make a shortcut without the IF statement to make it just run straight off. I won't make that mistake again....

Thanks a million for your help mate.
Title: Re: Dialog_Request script
Post by: Khris on Tue 30/01/2007 21:37:12
Theoretically you don't need to put the code inside an if-block, but then run-script x will always run the whole code, no matter what the x is.

Just a side note about the indentation of the paranthesis:

I'd do it this way:
Ã,  Ã,  ...
Ã,  Ã,  character[BUT].Walk(224, 147);
Ã,  Ã,  character[BUT].ChangeView(7);
Ã,  }
}


Looks cleaner, IMO.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 21:59:21
Yea you're right..

Humm i just need a little more help please if thats ok....

I am trying to write a script in the Character interaction menu for an NPC, so that when i talk to him in a certain room the main character will walk to specific co-ordinates only in that room. Rather than always walking to the same spot no matter what room he's in...because this NPC moves to different rooms.

I know the basis to the code, which is If Character is in Room(X) Then Character Walks to (X, X)...
but all i can think about is QBASIC language and there doesn't seem to be any THEN statements in AGS. So i'm a bit lost.

Thanks
Title: Re: Dialog_Request script
Post by: Khris on Tue 30/01/2007 22:15:29
No then here, no.

if (condition) {
Ã,  doStuff;
Ã,  doMoreStuff;
Ã,  doEvenMoreStuff;
}

If only one command is to be run dependant on the condition, there's no need to put it inside the {}.

if (rain_falls) BringUmbrella;

Else if and else are put below:

if (a==1) Display("a equals 1.");
else if (a==2) Display("a equals 2.");
else Display("a is neither 1 nor 2.");

Or the long version:

if (a==1) {
Ã,  Display("a equals 1.");
Ã,  Display("Additional info.");
}
else if (a==2) {
Ã,  Display("a equals 2.");
Ã,  Display("So a is the lowest prime number.");
}
else Display("a is neither 1 nor 2.");

It's in the manual (http://www.adventuregamestudio.co.uk/manual/ifelsestatements.htm), too.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 22:47:47
I'm still missing something. Or doing something completely wrong here i have done 2 variations of this script. and none seem to work, I just can't think about it in the right way. My brain has broken.

Heres the first one::::
// script for Character 0 (Butler): Talk to characterÃ, 
if (Room = 2) {
Ã,  character[LAM].Walk(238, 141);
Ã,  }

Second one::::

if (Room = 2) Character[LAM].Walk(238, 141);

It keeps saying Parse Error in expr near Room
Title: Re: Dialog_Request script
Post by: Ashen on Tue 30/01/2007 23:05:13
It's == for checking variables (as in if (Room == 2)), which'll be what's causing the parse error.

Secondly, is Room a variable you've declared? If not, you might get an error there as well. Do you want to check the room the player is in? That'd be player.Room, or other characters can be checked, e,g, cLam.Room.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 23:12:17
I think thats my problem, I do not know how to declare variables in AGS. I don't need to check what room the character is in myself....But do i have to check it for the game to know what room a character is in?
Title: Re: Dialog_Request script
Post by: Ashen on Tue 30/01/2007 23:15:10
Try the manual (http://www.adventuregamestudio.co.uk/manual/Datatypes.htm), or the BFAQ (http://americangirlscouts.org/agswiki/Scripting%2C_Code_%26_Interaction#Working_with_variables:_the_basics).
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 23:21:24
Ok i understood all that anyway.
This would be correct....

int Room;
Room = 2;

But thats not what i want, Thats just saying the Variable "room" = 2.....and the script doesn't know that i mean "The Actual Room Number 2". Isn't there a variable type for this kind of thing? Do i need to do a function command? Like i said  i'm real lost here and my brain just can't get around how this specific script needs to be run to get it to work.

Title: Re: Dialog_Request script
Post by: Ashen on Tue 30/01/2007 23:27:14
Huh?
That code will create a variable called Room and set it to 2, yes. However, I'm not sure if you could create a variable called Room since there's already the Room properties (Room.Height, Room.Width, etc). There's also - as I mentioned in my last post - the Character.Room (http://www.adventuregamestudio.co.uk/manual/Character.Room.htm) property which you can use to check what actual room a character is in. Is that waht you want?

No offense here, but it really looks like you haven't even tried to use the manual, BFAQ or forums before posting.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Tue 30/01/2007 23:33:21
none taken although you are wrong, believe me i've been stuck on this for hours, and i've read & looked at every possible thing, and none of it makes sense to me, Forgive me for seeming so stupid.

if (cBut.Room == 2) character[LAM].Walk(238, 141); I did this and it Ran the game without moaning. Only when i Talk to the character he still doesn't walk anywhere....

Ok Ashen what i am trying to do here is when the butler is in Room 2 i want my character to walk to a specific position to talk to him. When the butler is in Room 4 i want him to then go to the appropriate position to talk to him. Rather than not moving at all to speak to him or having to use 1 set or co-ordinates for the whole game.... I am running the script on the Character Interaction menu under "Talk To Character"
Title: Re: Dialog_Request script
Post by: Ashen on Tue 30/01/2007 23:59:11
Quote from: The Manual, Character.Walk
If blocking is eNoBlock (the default) then control returns to the script immediately, and the character will move in the background.

Try adding the eBlock parameter - it's possible any other code you're got (e.g. speech, or the ChangeRoom stuff) is 'cancelling' the non-blocking Walk command.
Title: Re: Dialog_Request script
Post by: Unknown_Terror on Wed 31/01/2007 00:39:25
Okay i managed to sort it out.

if (cBut.Room == 2) {
Ã,  character[LAM].Walk(236, 145, eBlock);
Ã,  character[LAM].FaceLocation(180, 127);
Ã,  dBUTLER.Start();
}

I know exactly what was going wrong and it's really a stupid thing, but anyone could make this mistake i guess.....What i was doing was this....

My run script looked like this Beforehand:

if (cBut.Room == 2) {
Ã,  character[LAM].Walk(236, 145, eBlock);
Ã,  character[LAM].FaceLocation(180, 127);
}

but the Problem actually was this:
(http://img259.imageshack.us/img259/8166/image3mx5.png) (http://imageshack.us)

It kept running the Dialog because it wasn't part of the Run-Script script, I didn't think it needed to be. I only found this out because it worked properly when i deleted the Run Dialog command, even without eBlock. So i am sorry for taking your time Ashen and thanks for the same thing. I am only a beginner at learning this language as u can obviously see, but i am definately learning some important things about how AGS works things out and how it runs.  Scripting is one thing.....But AGS's Engine is Another.