SendServerData: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<poem style="border: 2px solid #d6d2c5; background-color: #f9f4e6; padding: 1em;"> This function was added in v1.6 beta and will not work on previous versions. </poem>") |
No edit summary |
||
Line 2: | Line 2: | ||
This function was added in v1.6 beta and will not work on previous versions. | This function was added in v1.6 beta and will not work on previous versions. | ||
</poem> | </poem> | ||
{{Welcome| | |||
desc=This will send data( results in calling onClientScriptData of squirrel-server )| | |||
params=<syntaxhighlight lang="lua">(data)</syntaxhighlight> | |||
<poem>::data: The blob which needs to be formatted as below.</poem>| | |||
example= | |||
<poem>Input npcscript</poem> | |||
<source lang="lua"> | |||
local b=blob(); | |||
b.writen( swap4(16), 'i' ); | |||
b.writen( 1234, 'i' ); | |||
b.writen( 10, 'b' ); //b - byte | |||
b.writen( swap2(5), 'w' ); //w - word | |||
b.writen('h','c'); //c - signed char | |||
b.writen('e','c'); | |||
b.writen('l','c'); | |||
b.writen('l','c'); | |||
b.writen('o','c'); | |||
b.writen(100.789, 'f'); //f float | |||
SendServerData(b); | |||
</source> | |||
<poem>Output from server</poem> | |||
<source lang="lua"> | |||
function onClientScriptData(p){ | |||
print(Stream.ReadInt());print(Stream.ReadByte()); | |||
print(Stream.ReadString());print(Stream.ReadFloat()); | |||
} | |||
[SCRIPT] 1234 | |||
[SCRIPT] 10 | |||
[SCRIPT] hello | |||
[SCRIPT] 100.789</source>| | |||
relfuncs=*[[SendCommand]] | |||
}} |
Revision as of 23:09, 20 January 2023
This function was added in v1.6 beta and will not work on previous versions.
Description:
This will send data( results in calling onClientScriptData of squirrel-server )
Parameters:
(data)
data: The blob which needs to be formatted as below.
Return Values:
This function does not return any specific values.
Example
Input npcscript
local b=blob(); b.writen( swap4(16), 'i' ); b.writen( 1234, 'i' ); b.writen( 10, 'b' ); //b - byte b.writen( swap2(5), 'w' ); //w - word b.writen('h','c'); //c - signed char b.writen('e','c'); b.writen('l','c'); b.writen('l','c'); b.writen('o','c'); b.writen(100.789, 'f'); //f float SendServerData(b);
Output from server
function onClientScriptData(p){ print(Stream.ReadInt());print(Stream.ReadByte()); print(Stream.ReadString());print(Stream.ReadFloat()); } [SCRIPT] 1234 [SCRIPT] 10 [SCRIPT] hello [SCRIPT] 100.789
Related Functions
The following functions may be helpful as they relate to this function in one way or another.