Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-05-2011, 06:41 PM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Send a param with catchEvent?

is it possible to send a param with catchEvent?

such as I have these in a GuiShowImgCtrl of a character

PHP Code:
thiso.catchEventname"onMouseDown""RotateChar");  
thiso.catchEventname"onRightMouseDown""RotateChar"); 
in the function 'rotateChar' I can't determine which button was clicked as leftmousedown returns false.

I know I could make two short functions but I was wondering if I could combine them. Both attempts when I try to send a param fails to get the event, my question is moreso how to determine which mouse button was pressed?
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #2  
Old 03-05-2011, 07:02 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
afaik it's not possible without separate functions

use this instead of name when you're catching events.

PHP Code:
thiso.catchEventname"onMouseDown""RotateChar");  
thiso.catchEventname"onRightMouseDown""RotateChar"); 
should be

PHP Code:
thiso.catchEventthis"onMouseDown""RotateChar");  
thiso.catchEventthis"onRightMouseDown""RotateChar"); 
the name stuff only works through some silly guessing stuff in the engine (same reason profile = "ProfileName" works?).
__________________
Reply With Quote
  #3  
Old 03-06-2011, 12:36 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Quote:
Originally Posted by cbk1994 View Post
the name stuff only works through some silly guessing stuff in the engine (same reason profile = "ProfileName" works?).
So is using 'this' just more efficient than 'name'? Or is it just a preference choice and trivial?
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #4  
Old 03-06-2011, 12:51 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by MrOmega View Post
So is using 'this' just more efficient than 'name'? Or is it just a preference choice and trivial?
It's not personal preference, it's the proper way to do it. You're giving it a string when it's expecting an object.

Proof, from a wiki article written by Stefan:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
// Retrieve the playlist via http
  
this.req requestURL("[link removed]");
  
catchevent(this.req,"onReceiveData","onData");

__________________
Reply With Quote
  #5  
Old 03-06-2011, 01:39 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
I'm pretty sure when you catch an event you'll get the same arguments as when you just handle the event directly (i.e. MyControl.onMouseDown(...)). And the first argument for onMouseDown() is the mouse button iirc:
PHP Code:
thiso.catchEvent(this"onMouseDown""RotateChar");

//...

function RotateChar(butt) {
  if (
temp.butt == "right") {
    
// stuff
  
}

__________________
Reply With Quote
  #6  
Old 03-06-2011, 03:26 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Why does the wiki show it as:
Quote:
catchevent(str,str,str)
adds an event handler for the specified object name and event, third parameter is the name of the function which receives the event (first parameter of the event will be the object for which the event occured)
http://www.graal.net/index.php/Creat...ient/TGraalVar
__________________
Reply With Quote
  #7  
Old 03-06-2011, 03:30 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by 0PiX0 View Post
The wiki is wrong. It also endorses such travesties as using quotes around a GUI profile.

I suppose I could be wrong about this, but it seems very unlikely to me that Stefan would accept the name of an object rather than the object. It's like sending the player's account to a function instead of the player object—it doesn't make sense.

In addition,

Quote:
Originally Posted by scripthelp
TGraalVar.catchevent(str, str, str) - adds an event handler for the specified object and event, third parameter is the function which receives the event (first parameter of the event will be the object for which the event occured)
__________________
Reply With Quote
  #8  
Old 03-06-2011, 03:31 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
It would be funny if it coerced the object into its name, and then back into an object to actually apply the relevant changes to it in order to catch the event.
Reply With Quote
  #9  
Old 03-06-2011, 06:25 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
My whole question is, if it works, why is it allowed? I do use quotes for guiProfile names too, just purely because it highlights the names. Which I like.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #10  
Old 03-06-2011, 06:33 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by MrOmega View Post
My whole question is, if it works, why is it allowed?
GS2 is dynamically typed, so values are coerced based on whatever type they need to be. It's usually a Bad Idea™ to rely on the coercing though because it is sometimes unclear what is happening.

For example, you can check if a value exists like this:
PHP Code:
if (temp.someValue) {
// ...

However, what is really happening there, is temp.someValue is being coerced to a boolean (true/false). It will actually coerce to false in the case of say, temp.someValue = "0" or temp.someValue = 0, thus making the if statement not work even though the value does exist.

Basically, relying on the coercing can make strange bugs crop up in edge cases that are hard to find until they actually break something. It's usually best to be explicit.


I personally dislike dynamically typed languages and think they should slowly fade out of existence.
Reply With Quote
Reply


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 02:52 PM.


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