Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tyr on Sat 08/08/2009 17:22:48

Title: Altering rooms from dialogue?
Post by: Tyr on Sat 08/08/2009 17:22:48
I've tried to find the answer for this everywhere but can't figure it out, dialog is just so damn hard.
I've got my dialog- the player asks another character if he can have something, the other character says yes and gives the player it.
Now. The problem is this item is also connected with a object in a certain room.

I can add the item to the inventory no problem however all attempts at making the object invisible fail drastically. I keep being told room1 is undefined and that sort of thing.
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Sat 08/08/2009 17:29:52
If you're in the same room as the object then you should be able to use the global object array:

// dialog script
  if (blah) object[27].Visible = true;


Note that you would not be able to use the object's script name (such as oKey), you would have to pass the ID directly.

If the object is in a different room then you would have to use some type of global variable to track the status and then update the object in that room's OnLoad, BeforeFadein, or AfterFadein event handler.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Sat 08/08/2009 19:39:42
Ah thanks. Works straight away.

I was trying all sorts of crap to do it - trying to pass booleans between dialog, global and local and all sorts of stuff. And it turns out to be a simple thing... I hate it when that happens.
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Sat 08/08/2009 19:49:50
Glad you got it sorted out. Since objects are stored within a specific room, they are only loaded when that room is loaded. The names like "oKey" aren't defined globally since the objects don't exist globally.

Because of this if you need to reference an object outside of a room script you have to do it using the generic object array. Just keep that in mind and you should be good to go.

Oh and another important thing to note is that if you're working with the global object array it might be a good idea to check the player's room (player.Room) just to make sure you're in the right room. ;)
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Sat 08/08/2009 20:51:48
While I'm here to save creating a new thread (I'm really asking too much lately...total newbie);
How do you activate animations?

I've got a extra view created after the empty diagonal loops to use when I want the character to pick something up and then ultimatly I'll be wanting talking loops too.
How do you trigger these?
Title: Re: Altering rooms from dialogue?
Post by: Khris on Sat 08/08/2009 21:05:12
May I suggest reading the tutorial in the manual...?  :=
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Sat 08/08/2009 21:55:07
The function you would use to actually run the animation would be Character.Animate. Where you call it depends what you're doing. For example if you wanted to pick up an object in the room, and animate the character bending down, then you would call it in the inventory item's event handler for the eModePickup cursor mode.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Sun 09/08/2009 14:02:01
Quote from: KhrisMUC on Sat 08/08/2009 21:05:12
May I suggest reading the tutorial in the manual...?  :=
It wasn't there.
Its explanations of views doesn't go beyond walk directions which of course are automatic.



Character.animate, right. Right, I'll look in that direction.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Mon 10/08/2009 17:42:12
character.animate it was indeed.  ;D

Something I'm unsure of in this- how would I have something carried over from a discussion?
There is a point where the player needs to ask the character a question to learn something.
I've got a global variable bool knowscode but trying to set knowscode=true in the discussion says it is undefined.
How do you pass variables between the discussions and globals and rooms?
Title: Re: Altering rooms from dialogue?
Post by: Khris on Mon 10/08/2009 18:06:48
Did you create the variable in the Global variables pane?
Did you put a space before the line in the dialog script?
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Mon 10/08/2009 18:08:27
Is this the error you're getting:

Unknown command: knowscode = true. The command may require parameters which you have not supplied.

Please note that to use "normal" scripting in a dialog script you must precede the line with at least one whitespace character, i.e.:

// blah blah
 knowscode = true; // this line starts with two spaces
// it also compiles fine


The reason for this is that the dialogs use a different, simplified scripting method to make it more like writing a narrative script:

EGO: Hello Bob!
BOB: Hello Roger!
 player.Say("To use normal scripting in a dialog script, start with a space!");


Khris beat me to it but oh well.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Mon 10/08/2009 19:48:16
Yeah its tabbed in dialogue (other code above that works fine).
And its defined as bool in the main globalscript.asc

The error is undefined token
Title: Re: Altering rooms from dialogue?
Post by: Khris on Mon 10/08/2009 19:53:41
Either remove the declaration and add the variable in the Global variables pane or add the necessary export/import lines.
And please show us your code.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Mon 10/08/2009 22:50:13
Quote from: KhrisMUC on Mon 10/08/2009 19:53:41
Either remove the declaration and add the variable in the Global variables pane or add the necessary export/import lines.
And please show us your code.

I don't understand you. Export/import lines?



At the top of globalscript I have
bool knowdog;

In the dialog is this option:

@2
sam: he shep. he nice
  knowdog=true;
return


this will then be used when the player talks to shep with a if he knows his name or not.
Title: Re: Altering rooms from dialogue?
Post by: Matti on Mon 10/08/2009 23:07:50
// at the end of the globalscript:

export knowdog;

// at the start of the room script:

import bool knowdog;


This isn't necessary if you're declaring the bool via the global variables pane..
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Mon 10/08/2009 23:08:07
Yes, import (http://www.americangirlscouts.org/agswiki/Script_language_keywords#import) and export (http://www.americangirlscouts.org/agswiki/Script_language_keywords#export). When someone references something that you're not sure what they're talking about you should look it up in the manual. There's a copy included with the editor. It's the file called "ags-help.chm" There's a copy online which is always kept up-to-date here (http://www.adventuregamestudio.co.uk/manual/). Finally there is a copy in the wiki here (http://www.americangirlscouts.org/agswiki/Contents_%28manual%29) which does get behind sometimes since it's not "official" but it is searchable.

Another great tool which can be used for searching is the forum search (http://www.adventuregamestudio.co.uk/yabb/index.php?action=search). I did a search for "import export" in the tech forums (Beginner's, Tech, and Module/Tech Archive) and got 12 pages. Not all of it relevant, but a lot of it would have included scripting examples.

Tyr, please, please, please...read. the. manual. BEFORE. asking.

I know you said you looked into how to trigger animations...but did you perhaps try going into the manual's index? I type "an"...just "an" and the first two entries listed are "Animate (button)" and "Animate (character)". I think that should have been enough to tip you off with some ideas.

Or if you use the search function in the manual...I typed in "animations". The very first page listed is "Character functions and properties". The third item on that page is "Animate (character)".

I'm not trying to be rude here, but Khris already suggested taking a look in the manual which you claimed to have done.

All I'm saying is people will be more likely to help you if you at least put forth some effort.

Everything you've done as far as the code is correct so far. The problem is that it's incomplete. If you look up the keywords "import" and "export" in the manual/wiki/forums/etc. then you should be able to get this running.

Or you could even do as Khris suggested and use the Global Variables pane which would do the work for you.

Mr Matti beat me to the punch and gave you the exact lines of script you need. You don't however have to put the import line into a room script. It can go into any script. The normal place to put it to make it global is just to put it into the header file ("*.ash") so it will automatically become available to every subsequent script.
Title: Re: Altering rooms from dialogue?
Post by: Matti on Mon 10/08/2009 23:16:33
Quote from: monkey_05_06 on Mon 10/08/2009 23:08:07
The normal place to put it to make it global is just to put it into the header file ("*.ash") so it will automatically become available to every subsequent script.

D'oh!

I know AGS for almost three years, but NEVER used the .ash to import global variables.... that could have saved me quite some time.

Thanks for pointing that out monkey. ;)
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Mon 10/08/2009 23:26:11
Sure thing! If you put it into a header file then it becomes available to every subsequent script (including GlobalScript.asc, all room, and dialog scripts). So for example if you have 3 scripts and you have an import in the second script header, then the first script won't have access to it. Keep that in mind.

Other than that though, as I said you can put an import anywhere you like really. The only difference it makes is the scope of your import. As I said if you put it into a header then it has scope, that is the variable/function exists, in every subsequent script. If you put an import in a room script then the variable/function can be used in that room, but not necessarily globally (depending where else it may be imported).

You can even put an import into a normal script. I often do this:

// somescript.asc
import function some_local_func(int param=27);

function some_local_func(int param) {
 // blah
}


To provide default parameters to localized functions. ;)

Oh and also, just so you know, the export line doesn't necessarily have to go at the end of the script either. So long as the export is after the variable it's exporting that's fine.
Title: Re: Altering rooms from dialogue?
Post by: Matti on Tue 11/08/2009 00:00:31
Okay, thanks. I'll see how I can use that in the future.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Tue 11/08/2009 16:41:55
Quote from: monkey_05_06 on Mon 10/08/2009 23:08:07

Tyr, please, please, please...read. the. manual. BEFORE. asking.

I'm not trying to be rude here, but Khris already suggested taking a look in the manual which you claimed to have done.

All I'm saying is people will be more likely to help you if you at least put forth some effort.

Except I did look. I was looking for a good two hours in vein and only asked as a last resort.


Trying to figure it out now with the new information. Thanks.
The problem seems to be right at the end. Importing it to the global file bitches that its already defined but not already defining it makes the dialogue complain about it not being defined...hmm....
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Tue 11/08/2009 18:46:13
Can you please post the code you're using? Because I just verified (again) that it does in fact work if you do it properly. It should look like this:

// GlobalScript.ash - ASH is the HEADER

import bool knowdog;

// GlobalScript.asc - ASC is the MAIN SCRIPT

bool knowdog;
export knowdog;

// dialog script
  knowdog = true;
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Tue 11/08/2009 18:59:32
Aha, that works great, thanks.
I think the problem was that I had the knowdog and the export in the header. I guessed that was the main thing.

So.... the header is just there to carry stuff and actual functions should all be the main one?
Title: Re: Altering rooms from dialogue?
Post by: monkey0506 on Tue 11/08/2009 19:13:32
Think of it like this...every header gets attached to the top of every script. So your GlobalScript.ash file will get attached to the top of each of your dialog scripts and your room scripts.

If you define a variable or function in any header (*.ash) file then it is going to create a new copy of that variable/function for every script.

If you import the variable or function in a header file, then the one and only copy of that variable/function that is defined is going to become accessible in every script.

The difference? If you define "knowdog" in the header, then change its value from one script, then check it in another script, you are no longer checking the same variable. If you were to import it (which is what you should do) then any changes to the "knowdog" variable will be reflected in all of your scripts.

Note that as I said before, imports only work on subsequent scripts. So if you create a script called "SomeScript" (which gives you SomeScript.ash, the header, and SomeScript.asc, the main script) and then you have an import in GlobalScript.ash, SomeScript.asc will never have access to that import. However, if you have an import in SomeScript.ash, GlobalScript.asc will have access. The headers only get included in the scripts that come after that header in the list of scripts; dialog and room scripts are always considered to be at the end of the list, after GlobalScript.

Further, although you must use the export keyword when working with variables, you do not use it for functions. Variables must be exported, both variables and functions must be imported, in order for these items to be accessible from a different script than the one in which they are defined.

Also, although it might not seem like that big of a deal for functions to have separate copies, don't put functions into any *.ash header file. All that will do is create duplicate copies of the function which will bloat the size of your compiled EXE, not to mention taking longer to compile since you would have to rebuild every single script every time (which can take a while if you have a large number of rooms). Always use imports in header files and define the variables/functions in the main script files.
Title: Re: Altering rooms from dialogue?
Post by: Tyr on Fri 14/08/2009 15:10:29
Aha right thanks, so its like a header included in web pages...I get it.