On_call function mysteries

Started by Mr_Threepwood, Fri 11/08/2006 18:38:57

Previous topic - Next topic

Mr_Threepwood

Alright I am a bit confused with the on_call room function that you use to do local room things from the global script.

The reason I am confused is that it seems to be able to access and change room variables just fine, but it can't call other room functions.

for example I have a function called startFireScene() and when I try to call it from the on_call function it won't work, but if you call it from any other room function it works just fine.

This got me to thinking that maybe the on_call function still counts as a global function that is specialized for that room, however it's not so since it can access and change room variables.  The biggest problem I have is that without the ability to call other room functions from the on call function it means that a few times I have to have duplicates of the exact same code.

For example I have a room variable called booksBurned that gets changed after something in the on call function happens, if two books are burned then a cutscene happens.  Well right now I have to have the cutscene cut and pasted into two of the spots in the on call, since the player may burn the books in a different order.

Is there any way to call room functions from the on_call function?

(the reason I used the on_call function was because it seems to be the most elegant way of making the character walk to an area and do something when they get there, without pausing the script).
I am a mighty pirate

monkey0506

How exactly do you have it scripted?

I've never used the on_call function before myself, but it seems that in your global script where you need to call the room script you use CallRoomScript, and then in the room script itself you put the on_call function like this:

Quote from: The Manualfunction on_call (int value) {
  if (value == 1) {
    // Check text input
    if (Parser.Said("get apple"))
      Display("No, leave the tree alone.");
  }
}

And...how exactly does the function not work? Is it not called, or does it not update properly, or what exactly?

I think it may be worthy of noting this:

Quote from: The ManualThe function doesn't get called immediately; instead, the engine will run it in due course, probably during the next game loop, so you can't use any values set by it immediately.

Once the on_call function has executed (or not if there isn't one), the game.roomscript_finished variable will be set to 1, so you can check for that in your repeatedly_execute script if you need to do something afterwards.

If the function seems as if it is never being called, you could put something like "Display("ECHO!");" just inside the function so you know whether it's actually getting called or not.

More information on what you have done would be helpful though.

Mr_Threepwood

Alright sorry I'll try to explain it better, but pasting code probably won't help since the way I have it set up is so complicated that you'd need all of the games global and room scripts to understand.

The original problem was this, I wanted to make it so you can do something like "open door" and your guy walks to the door and then when he reaches it he opens it.Ã,  On top of that I wanted it to be such that as you are walking to the door any click will cancel the movement and you will stay in the current room.Ã,  This same idea applys to every item in my game, IE if you click pick up on something your guy starts walking towards it then picks it up, but if you click somewhere before that he will go there instead and will not pick up the item.

To do this I made a global function called queuedCommand which basicly uses a bunch of things to tell if its in a queue and stuff, and when if it reaches the destination succesfully it calls the rooms on_call script and then does the action.

I've managed to get all of that working perfectly, so each room has its own on_call function implemented in it for queued commands.

The problem is that the on_call function seems to be a bit strange.Ã,  In the function it lets you call up variables that are unique to the room, so if I made a room variable called lightOn I can set it and read it from the on_call function.Ã,  This would make it seem like the on_call method is completely in the room script (which would make sense), however it has something different with it because you can not call other room functions from the on_call function.

so say in one room I have a function called doFireCutscene() and I want to call the function after a queued event, so I put it in the on_call function.Ã,  That won't work for some reason and I can't figure out why, it's definitly not spelling or something because if I call the doFireCutscene() function from any other room function (like after fade in) it will work.

This leads to problems because with in my queued commands there are multiple ways to get to the cutscene, so logicly it would be best to have a function which executes the cutscene rather than having the entire cutscene cut and pasted into multiple spots in the on_call function.Ã,  I can get it to work right now by doing just that, but if I do try and use a function to make it cleaner it won't let me.

Any ideas?

Again if this is hard to understand (I know it's pretty complicated) then I'll try to elaborate even more and provide some code snippets.Ã,  As I said though the codeing is very complicated since I could not figure out a more elegant way to do this with the AGS engine, it was kind of a workaroundsince you can't exactly call room functions from the global script (other than on_call which is exactly what I'm doing :) ).

Edit: so to sum up the problem isn't lack of executing, it's that AGS spits out an error when I try to call a room function from the on_call function.
I am a mighty pirate

Kweepa

Ah, you get an error.
(Posting the text of the error would be useful, now and in future.)
Perhaps it's just the function ordering.
Is on_call above the function you want to call in the room script?
Try putting on_call at the bottom of the script.
Still waiting for Purity of the Surf II

Mr_Threepwood

I was just getting a function undefined token, so I did as you suggested and put the on call below the function it had to call and then it worked, horray.

I didn't know that the order they appeared in the script made any difference so originaly I just had the function at the bottom.  I usually use java and there the order doesnt matter, so I guess it's just unique to AGS/c++.

Thanks.
I am a mighty pirate

SMF spam blocked by CleanTalk