JavaScript: ASLEvent
Sora574
11 May 2013, 06:09I've been messing around with multiplayer stuff a lot lately, and this has come up so many times, so here goes...
Is it possible to have multiple parameters for an ASLEvent in JavaScript?
For example:
This just makes everything look cleaner than
Especially with a different function, with a lot more parameters, and a lot of advanced JavaScript string holders that are actually used instead of just 'player' and 'room' (not to mention sending around the information between the server and clients)
Then, that brings up another question: Can JavaScript have support for Quest objects?
It doesn't seem like it currently does, because if you do something like...
...Then Quest says something about not being able to convert a string to an object, and in the log it says 'Moving [object Object] to room.'
I don't even know if it's possible to fix that, but I figured I'd ask.
Is it possible to have multiple parameters for an ASLEvent in JavaScript?
For example:
ASLEvent ('ServerMoveObject', 'player', 'room');
// Which calls this
<function name="ServerMoveObject" parameters="obj, loc">
MoveObject (GetObject(obj), GetObject(loc))
</function>
This just makes everything look cleaner than
ASLEvent ('ServerMoveObject', 'player; room');
<function name="ServerMoveObject" parameters="cmd">
l = Split (cmd, "; ")
object = GetObject(ToString(l[0]))
location = GetObject(ToString(l[1]))
MoveObject (object, location)
</function>
Especially with a different function, with a lot more parameters, and a lot of advanced JavaScript string holders that are actually used instead of just 'player' and 'room' (not to mention sending around the information between the server and clients)
Then, that brings up another question: Can JavaScript have support for Quest objects?
It doesn't seem like it currently does, because if you do something like...
JS.moveObjectToRoom (player)
// Then, the JavaScript for 'moveObjectToRoom'
function moveObjectToRoom (object) {
ASLEvent ('Log', 'Moving ' + object + ' to room.');
ASLEvent ('ServerMoveObjectToRoom', object);
}
// The Quest function 'ServerMoveObjectToRoom'
<function name="ServerMoveObjectToRoom" parameters="obj">
MoveObject (obj, room)
</function>
...Then Quest says something about not being able to convert a string to an object, and in the log it says 'Moving [object Object] to room.'
I don't even know if it's possible to fix that, but I figured I'd ask.

jaynabonne
11 May 2013, 08:04You're not able to do either of what you ask currently in the code. I have resorted myself to delimited text for ASLEvent parameters. It's just a single param function. Whether it's *possible* further down the road - that's for Alex to say, I suppose. 
Another really nice feature would to be able to get a return value from a JS call. That would allow offloading some intense processing to a JS function. Of course, you can always use ASLEvent to pass the result back, but it's just one more (damn) thing you have to do asynchronously (or "out of code")
(Have you been logging these requests as "issues" under "Report a Bug"? They're not technically bugs, but that is a place new feature requests can be communicated and tracked.)

Another really nice feature would to be able to get a return value from a JS call. That would allow offloading some intense processing to a JS function. Of course, you can always use ASLEvent to pass the result back, but it's just one more (damn) thing you have to do asynchronously (or "out of code")
(Have you been logging these requests as "issues" under "Report a Bug"? They're not technically bugs, but that is a place new feature requests can be communicated and tracked.)
Sora574
11 May 2013, 12:55Are you completely sure it isn't possible?
What's the JavaScript for the 'ASLEvent' function? Could there be a way to use whatever's in it to make a new function?
EDIT: By the way, no, I haven't logged them. Actually, I didn't even think about it.
What's the JavaScript for the 'ASLEvent' function? Could there be a way to use whatever's in it to make a new function?
EDIT: By the way, no, I haven't logged them. Actually, I didn't even think about it.

jaynabonne
11 May 2013, 13:11ASLEvent does this:
UIEvent is a VB function, which takes a single "args" string. For ASLEvent, it does this:
SendEvent is implemented in a C#. It does (among other things) this:
So a single parameter makes its way up. I definitely think it's possible, in the sense that the all this internal code could be modified to make it happen. But I don't see a way to make it happen just from javascript.
I think we could come up with a good protocol (string encoding) that would make lots of things easier - have a single ASLEvent target that takes not only multiple parameters but also an object/script to invoke. It would split out the parameters into a dictionary and the "do" the script with those params. Then it would all be below the covers. But we'd still have to feed it through a single string parameter. URLEncode, anyone?
function ASLEvent(event, parameter) {
UIEvent("ASLEvent", event + ";" + parameter);
}
UIEvent is a VB function, which takes a single "args" string. For ASLEvent, it does this:
Dim args As String() = data.Split({";"c}, 2)
RaiseEvent SendEvent(args(0), args(1))
SendEvent is implemented in a C#. It does (among other things) this:
Parameters parameters = new Parameters();
parameters.Add((string)handler.Fields[FieldDefinitions.ParamNames][0], param);
RunProcedure(eventName, parameters, false);
So a single parameter makes its way up. I definitely think it's possible, in the sense that the all this internal code could be modified to make it happen. But I don't see a way to make it happen just from javascript.
I think we could come up with a good protocol (string encoding) that would make lots of things easier - have a single ASLEvent target that takes not only multiple parameters but also an object/script to invoke. It would split out the parameters into a dictionary and the "do" the script with those params. Then it would all be below the covers. But we'd still have to feed it through a single string parameter. URLEncode, anyone?

Sora574
11 May 2013, 19:06Cool, I'll try playing around with that later.
Meanwhile, I'm gonna get set up for the multiplayer testing in a bit.
Meanwhile, I'm gonna get set up for the multiplayer testing in a bit.