interaction scripts?

Started by stuh505, Sat 06/11/2004 18:49:50

Previous topic - Next topic

stuh505

where do I put a script to have it execute on an interaction event that happens for all rooms?

Edwin Xie

I believe it is function repeatedly_execute.  ;)
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

stuh505

I don't want them to repeatedly execute, I want them to execute when the certain interaction events of a room get triggered.

Goot

make a function for it in the global script.

function function_name(){
script here;
}

in the script header (script>script header, below the place you click to get to the global script):

import function function_name();

in any script:

function name(); //runs the script inside th function brackets in
//the global script

stuh505

Goot:

I'm not asking how to call a function from a room's interaction script...I want the function to be called whenever a specific interraction event gets triggered regardless of what room it is in...without having to copy and paste the function calls into every room interaction event

Ashen

What exactly is the trigger event? Since that probably effects where you'd but the script.
I know what you're thinking ... Don't think that.

Edwin Xie

#6
When you put the scripts in repeatedly execute it doesn't specifically have to be repeatedly executed. This can be done with if statements.

EDIT: Or do you mean unhandled_event? As described from the manual:
Quoteunhandled_event (int what, int type)
Called when an interaction is run, but no events are listed in the interaction window. This could be used to display a default "I can't do that" type of message. The values of WHAT and TYPE tell you what the player did.
The possible values are listed below:

WHAT TYPE Description
1    1   Look at hotspot
1    2   Interact with hotspot
1    3   Use inventory on hotspot
1    4   Talk to hotspot
1    7   Pick up hotspot
1    8   Cursor Mode 8 on hotspot
1    9   Cursor Mode 9 on hotspot
2    0   Look at object
2    1   Interact with object
2    2   Talk to object
2    3   Use inventory on object
2    5   Pick up object
2    6   Cursor Mode 8 on object
2    7   Cursor Mode 9 on object
3    0   Look at character
3    1   Interact with character
3    2   Speak to character
3    3   Use inventory on character
3    5   Pick up character
3    6   Cursor Mode 8 on character
3    7   Cursor Mode 9 on character
4    1   Look at nothing (ie. no hotspot)
4    2   Interact with nothing
4    3   Use inventory with nothing
4    4   Talk to nothing
5    0   Look at inventory
5    1   Interact with inventory (currently not possible)
5    2   Speak to inventory
5    3   Use an inventory item on another
5    4   Other click on inventory
Note that the "Character stands on hotspot" event does not trigger this function, and it will not be triggered if there is an "Any click" interaction defined. This function is not triggered if the player clicks on nothing (hotspot 0).
The on_key_press and on_mouse_click events can also be handled by individual room scripts. If you add their function definitions to your room script in a similar way to how they are in the global script, the room script can intercept the keypress/mouseclick first, and then decide whether to pass it on to the global script or not. See the ClaimEvent function for more.

Or maybe you want on_event?
Quoteon_event (int event, int data)
Called whenever certain game events happen. The value of DATA depends on which event has occured. This allows you to perform checks or update things every time the player does something, regardless of which room it is in. The possible values of event are:

ENTER_ROOM    called just before room Player Enters Screen event is run.
              DATA = new room number
LEAVE_ROOM    called just after room Player Leaves Screen event is run.
              DATA = room number they are leaving
GOT_SCORE     called whenever the player's score changes
              DATA = number of points they got
GUI_MDOWN     mouse button pressed over a gui
              DATA = GUI number
GUI_MUP       mouse button released
              DATA = GUI number it was pressed down over
ADD_INVENTORY the player just got a new inventory item
              DATA = inventory item number that was added
LOSE_INVENTORY the player just lost an inventory item
              DATA = inventory item number that was lost
RESTORE_GAME  tells your game that it has just been restored from a save game
              DATA = save slot number
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

stuh505

Edwin, thanks that is what I was looking for.

In this case, I wanted to do it for the Player Enters Screen (after fade in).  There doesn't seem to be an event for this even though it is an interaction event...I could jimmy this to work this a Timer, but that's a little crude.

Can you explain how the unhandled events work a little more?  The "what" and "type" classify the action...but how do you know what the target of the action was?  For example, "Look at hotspot"...how do you know which hotspot they tried to look at?

Edwin Xie

I believe what you are looking for is the on_event, unhandled_event only does something when the player interacts with something while on_event is an event done by the game. You understand? If you don't know how I got this, look closely...
Quote
on_event (int event, int data)
Called whenever certain game events happen.
And what you are looking for is
Quote
on_event (int event, int data)
.......
ENTER_ROOM    called just before room Player Enters Screen event is run.
              DATA = new room number

I don't really know how you can really classify the hotspot. Perhaps the advanced scripters will know...
*Edwin looks at them...
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Ashen

unhandled_event is for, well, unhandled events - i.e. when the player clicks on something that doesn't have an interaction set, it does something like display an "I can't do that", "That won't work", "I don't see anything special" kind of thing. So, basicly, it doesn't know which hotspot the player looked at, only that it was one without a 'Look at' action defined. If you want to specify which one, you just have to add a couple of extra 'if' conditions, e.g.
Code: ags

function unhandled_event (int what, int type) {
if (what == 0) {
  if (type == 1) { //if 'Look at Hotspot'
    if (GetHotspotAt (mouse.x, mouse.y) == 3) { //if 'Look at Hotspot 3'
      Display ("That's hospot number three.");
    }
    else { // if looking at a hotspot other than 3, with no 'Look at' action
      Display ("I don't know what that is, but it's not hotspot number 3.");
  }
}
}


You could also add an if (player.room == x) condtion, but really you'd be better just setting the Hotspot interaction directly.

I don't think there's an on_event event for after fade in, so you'd either have to use a timer, as you said, or type the script in every room. You could put it all into a custom function, though, so you'd only have to copy-paste one line.
I know what you're thinking ... Don't think that.

Edwin Xie

#10
Ah! Why couldn't I have found that out? Interesting use though.

EDIT: Hmm, you are right, it doesn't have anything for after the screen fades in Player Enters Screen.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

strazer

QuoteHmm, you are right, it doesn't have anything for after the screen fades in Player Enters Screen.

It's on the tracker: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=479

Edwin Xie

Meh, it's too late, 2.62 final is already released....or is it?
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

SMF spam blocked by CleanTalk