Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-13-2008, 03:22 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Here is an alternative.
PHP Code:
function onActionGrab() {
  
this.level.chair.trigger("ActionShock""");

PHP Code:
function onCreated() {
  
this.setshape(13232);
  
this.level.chair this;
}
function 
onActionShock() {
  
// do stuff

The this. prefix isn't required in this instance but it is my preference to do it like that so you clearly know what the variable belongs to.
__________________

Last edited by Inverness; 08-13-2008 at 04:54 PM..
Reply With Quote
  #2  
Old 08-17-2008, 01:41 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Quote:
Originally Posted by Inverness View Post
Here is an alternative.
PHP Code:
function onActionGrab() {
  
this.level.chair.trigger("ActionShock""");

PHP Code:
function onCreated() {
  
this.setshape(13232);
  
this.level.chair this;
}
function 
onActionShock() {
  
// do stuff

The this. prefix isn't required in this instance but it is my preference to do it like that so you clearly know what the variable belongs to.
I like this idea, I didn't think of this! [However, you'd need to remove the 'this.level.chair' to replace it with 'level.chat' and also make the 'onActionShock' a public function]
Reply With Quote
  #3  
Old 08-17-2008, 01:54 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by [email protected] View Post
However, you'd need to remove the 'this.level.chair' to replace it with 'level.chat'
No you don't. And I assume you meant level.chair. In an NPC, this.level.chair is the same as level.chair because static (built-in) variables can be accessed with or without the this. prefix.
Quote:
Originally Posted by [email protected] View Post
and also make the 'onActionShock' a public function
No you don't, it only needs to be public if you're calling it. You can trigger events even if they're not public.

Function Call: this.level.chair.onActionShock();
Calling a function means its on the same thread so that function must complete before the script can continue to next statement. To call a function in a different object it needs to be public.

Event Trigger: this.level.chair.trigger("ActionShock", null);
Triggering an event means its on a different thread, so it means the script that triggered it will continue to next statement while the onActionShock executes at the same time. An event does not need to be public to trigger it because the trigger function is public and that is the function you are using.
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.