Pio Posted April 12, 2015 Share Posted April 12, 2015 Hey. I have a little problem - idk if I made a mistake there, maybe I need to know something , or it is a bug. Can some1 explain me how it works and what can I do to be sure it's all ok. So, I want to do a simple script executed on event "onGamemodeMapStart" (mapmanager triggers that), and send some map info but it looks like arguments are delayed. There's my example script: Server-side: addEventHandler("onGamemodeMapStart", root, function(mapResource) local mapRoot = getResourceRootElement(mapResource) local previews = getElementsByType("preview", mapRoot) outputChatBox("<server>") outputChatBox(getElementType(previews[1])) outputChatBox("</server>") triggerClientEvent("onServerSendInfo", resourceRoot, previews) end ) Client-side: addEvent("onServerSendInfo", true) addEventHandler("onServerSendInfo", resourceRoot, function(theInfo) outputChatBox("<now>") outputChatBox(getElementType(theInfo[1])) outputChatBox("</now>") setTimer( function() outputChatBox("<50ms>") outputChatBox(getElementType(theInfo[1])) outputChatBox("</50ms>") end , 50, 1) end ) Now, when I start a map, with any "preview" element, client gets them, but not at the event time (is delayed). There is client output: <now> </now> <server> preview </server> <50ms> preview </50ms> Tag "now" pops up first (before "server") -> for client it looks that triggerServerEvent executed before outputChatBox right? And the "now" tag has no value, after 50ms it has. (sometimes 50ms is not enought and this tag is also empty) Why is that? Link to comment
xXMADEXx Posted April 12, 2015 Share Posted April 12, 2015 Try to concatenate the variable into the string with the message. addEvent ( "onServerSendInfo", true ); addEventHandler ( "onServerSendInfo", root, function ( info ) outputChatBox ( ""..tostring(getElementType(info[1])).."" ); end ); Link to comment
Pio Posted April 12, 2015 Author Share Posted April 12, 2015 Hey xXMADEXx. That's not the problem - in 50ms tag It's ok. But I tried that and it breaks that function (if after that is timer and it doesn't execute). info[1] is still nil value when used too early. Client debugscript says (on both versions): attempt to index global 'info' (a nil value). Link to comment
Pio Posted April 15, 2015 Author Share Posted April 15, 2015 I guess there is special priority for sending data between client and server for events, so references for elements can be recieved before the elements data (sent with normal priority), and that's why they are nil for some time. In my script I don't need that data instantly (in event time), so I solved this by re-checking with timer (every 50ms) if it's element or not. If I'm wrong then please correct me. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now