on_call not being called by CallRoomScript [SOLVED]

Started by paolo, Wed 19/09/2007 10:33:52

Previous topic - Next topic

paolo

I want to be able to manipulate a room object in the current room from the global script.

Currently I'm using on_call() and CallRoomScript(), as follows:

In my global script (note the diagnostic messages)

Display("About to call on_call()");
CallRoomScript(1);
Display("Returned from on_call()");

In the script for the room that is current when CallRoomScript() is called:

function on_call(int value)
{
  Display("In on_call(); value == %d", value);
  //blah
}


When I run my script, the messages displayed are:

About to call on_call()
Returned from on_call()

which shows that the function wasn't called.

What am I doing wrong? Incidentally, I wrote on_call at the end of my room script just by opening the whole room script in the editor (rather than just a section of it). Is it meant to be in a section (with grey start and end lines)? There doesn't seem to be a menu option for on_call anywhere.

Alternatively, is there a way of directly accessing and manipulating room objects from the global script? Something like the following:

room[n].objects[m].SetPosition(x, y);

Thanks.

Ashen

Odd, it works for me - well, kinda. In the CallRoomScript entry, describing on_call, the manual says:
Quote
The 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.

Which seems to be what happens for me. I get all 3 message, but in the order:
  About to call on_call()
  Returned from on_call()
  In on_call(); value == 1

Is it possible you clicked through the third message without realising?

There doesn't seem to be a way around this, unfortunately. Well, you might be able to figure out something using the game.roomscript_finished variable, but that'd be the only way.

on_call doesn't need the grey sectionstart/end lines - actually no function really does; they're included in the 'built in' functions for ease of navigation, but aren't required for the functions to work - so if the code you showed is what's in yur game, there's no reason it shouldn't work properly. (Provided you're actually in the same room as the on_call, of course...)

Objects can be refered to in Global Script by their number, but not by Script-o-name (so, e.g., object[0], but not oDoor). There's also the player.Room property to narrow it down further:
Code: ags

if (player.Room == n) object[m].SetPosition(x, y);
else if (player.Room == p) object[q].SetPosition(x2, y2);
// etc
I know what you're thinking ... Don't think that.

paolo

OK, that makes sense. I remember reading that in the manual but didn't pay too much attention to it. Looks like I should have done!

I killed the game and posted after getting just the two messages. If I'd let it continue, I would have seen the block of code in the global script being run to its conclusion and then the code in on_call() being executed, which is effectively what you saw too.

I don't know why I didn't realise that you could refer to objects in the room in the global script - you can do the same with characters, etc, so of course you can with objects too. I've got rid of the on_call function, moved the code into my global script and used object object[] to access the object, and it now all works as it should.

So there's another one solved (and the thread title updated accordingly). Thanks.

Khris

Quote from: paolo on Wed 19/09/2007 19:40:56I don't know why I didn't realise that you could refer to objects in the room in the global script - you can do the same with characters, etc
Well, your conclusion is right, but the premise isn't.

Of course it would be pretty bad if one couldn't refer to objects, hotspots or regions in the global script, so it's good one can by using the respective array.

But characters, as well as inv items and other global stuff are exactly that - global; contrary to room-dependent stuff like e.g. objects.
Thus they can also conveniently be referred to by their Scriptnames.

Just wanted to point it out :P

SMF spam blocked by CleanTalk