Snoozy Posted January 6, 2011 Share Posted January 6, 2011 Hey uhm so I'm having this issue, first it seems that some functions are just auto running when a player joins the server (Client side) is there a way to prevent the function from just running until it have been called, for example this one: function charSelect() createCharWindow() guiSetVisible(windowLogin, false) if (charWindow ~= nil) then guiSetVisible(charWindow,true) else outputChatBox("Problem! (For scripting testing purposes)",getLocalPlayer()) end end addEvent("onCharSelect",true) addEventHandler("onCharSelect",getRootElement(),charSelect()) That thing is already running before even being called from server And the strange thing is it's giving the error meaning the window was not successfully made what I don't get is, why? function createCharWindow() local charWindow = guiCreateWindow ( 0, 0, 0.5, 0.4, "Information", true ) local tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, charWindow ) local inf1 = guiCreateTab(getElementData(getLocalPlayer(),"tabinf1"), tabPanel ) local inf2 = guiCreateTab(getElementData(getLocalPlayer(),"tabinf2"), tabPanel ) guiSetVisible(charWindow,false) end Now this is the two serverside functions, the problem was that the upper lua code was already executed at start which not really is what I'm trying to do. Heres serverside to just trigger triggerClientEvent("onCharSelect",getRootElement()) Link to comment
SDK Posted January 6, 2011 Share Posted January 6, 2011 When the lua file get's loaded, all code that's not in function() ... end stuff gets executed immediately, and I guess that line is the only one you added in the server file. For your window, you can't use local in createCharWindow, else it will not exist outside that function scope. Client: local charWindow = nil function charSelect() createCharWindow() guiSetVisible(windowLogin, false) if (not charWindow) then -- don't use "~= nil", it can be false and "false ~= nil" => true guiSetVisible(charWindow,true) else outputChatBox("Problem! (For scripting testing purposes)",getLocalPlayer()) end end addEvent("onCharSelect",true) addEventHandler("onCharSelect",getRootElement(),charSelect()) function createCharWindow() charWindow = guiCreateWindow ( 0, 0, 0.5, 0.4, "Information", true ) local tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, charWindow ) local inf1 = guiCreateTab(getElementData(getLocalPlayer(),"tabinf1"), tabPanel ) local inf2 = guiCreateTab(getElementData(getLocalPlayer(),"tabinf2"), tabPanel ) guiSetVisible(charWindow,false) end Server: function testclientwindow (player, command) triggerClientEvent(player, "onCharSelect", getRootElement() ) end addCommandHandler("testgui", testclientwindow) Link to comment
Snoozy Posted January 6, 2011 Author Share Posted January 6, 2011 Okay uhm it did to some extent help I believe however it's not fully working yet, the problem right now is that When It's supposed to run the triggerClientEvent() I don't know whether it run it or not or what's going on but nothing that is supposed to happen charSelect function doesn't happen I'm sure the code before triggerClientEvent works cause right before that trigger function is starting a output code: outputChatBox("Logged into account, redirecting to Character Select",source) And that is being shown on screen right after that the code: (triggerClientEvent()) is triggerClientEvent(source,"onCharSelect",getRootElement()) The function charSelect is looking as you made it up in above post. Link to comment
SDK Posted January 6, 2011 Share Posted January 6, 2011 Yeah, found the problem. You should really start debugging btw, I didn't test the code but you did, and it would certainly throw an error. Use "/debugscript 3" in your testing server. addEventHandler("onCharSelect",getRootElement(),charSelect) Link to comment
Snoozy Posted January 6, 2011 Author Share Posted January 6, 2011 Is there a /deubscript 3 builtin function for ingame testing? Are you serious? I need to learn to actually read the wiki instead of just flashing through it I guess 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