Altering rooms from dialogue?

Started by Tyr, Sat 08/08/2009 17:22:48

Previous topic - Next topic

Tyr

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.

monkey0506

If you're in the same room as the object then you should be able to use the global object array:

Code: ags
// 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.

Tyr

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.

monkey0506

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. ;)

Tyr

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?

Khris

May I suggest reading the tutorial in the manual...?  :=

monkey0506

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.

Tyr

#7
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.

Tyr

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?

Khris

Did you create the variable in the Global variables pane?
Did you put a space before the line in the dialog script?

monkey0506

Is this the error you're getting:

Code: ags
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.:

Code: ags
// 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:

Code: ags
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.

Tyr

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

Khris

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.

Tyr

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.

Matti

// 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..

monkey0506

#15
Yes, import and 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. Finally there is a copy in the wiki here 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. 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.

Matti

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. ;)

monkey0506

#17
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:

Code: ags
// 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.

Matti

Okay, thanks. I'll see how I can use that in the future.

Tyr

#19
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....

SMF spam blocked by CleanTalk