Variables on the client are not the same as variables on the server. (Edit: by this I mean if you set a variable on the client to something, the one on the server with the same name won't change)
You need to use usermessage or something
Hey lua experts!
I'm trying to develop a custom extension for E2 which detects key presses on clients. The overall objective is to be able to tell when a client presses any key on their keyboard. Below i've included some code which I cannot get to work. When executing printingTest() in an expression with an interval of 1, "0" is printed to the console over and over again, no matter if i press "w" or not.
The client side code appears to be the problem. I know the code should work because i've tested it through the ingame console using the following command:Code:local I = 0 if (CLIENT) then hook.Add("Think", "e2thinker", function() if(input.IsKeyDown(33)) then I = I + 1 end end) elseif (SERVER) then registerFunction("printingTest", "", "", function(self) print(I) end) end
It works great, but practically the same code in a lua file in the e2 custom directory doesn't work. Any ideas?Code:lua_run_cl hook.Add("Think", "e2thinker", function() if(input.IsKeyDown(33)) then print("pressing w") end end)
Variables on the client are not the same as variables on the server. (Edit: by this I mean if you set a variable on the client to something, the one on the server with the same name won't change)
You need to use usermessage or something
Last edited by Divran; 01-29-2010 at 01:53 AM.
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
iirc, there already is such an addon. if you just code it again for fun, i can't help since my lua skills are very... basic.
DO YOU HEAR THE VOICES TOO?
Thanks for the response.
I am aware of the already existing Input Support extension. Unfortunately the client side of Input Support does not work and no one is helping on the Input Support forum. I decided to try identifying the cause of the problem myself but have come to find there must be something that changed to break the client-side functionality.
I didn't know that, thanks for the info.
I did try to use usermessage, but that didn't work either. I will have to wait till I get home to provide examples, but the client usermessage hook does not catch the messages i send. I get an error in the console saying something about an unhanded message. I'll post later with more details. I think this is why Input Support no longer works, it uses usermessage.
So here is an example using usermessage, and sendusermessage. They both do the same thing according to the wiki so i figured i would try both. Neither reach the client.
If you run "queryClient()" with an interval in e2, you will see the following over and over in the console:Code:if (CLIENT) then usermessage.Hook("runMe", function() Msg("Client received message") RunConsoleCommand("e2keystate") end) elseif (SERVER) then concommand.Add( "e2keystate", function( player, command ) print("I got here") end) local RP = RecipientFilter() RP:AddAllPlayers() registerFunction("queryClient", "", "", function() umsg.Start("runMe", RP) umsg.End() // SendUserMessage("runMe") end) end
Code:Warning: Unhandled usermessage 'runMe'
I think the client side functions need to be in a file prefixed by "cl_" in the custom folder in E2. Not sure though.
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
I've not done much with splitting the files like this but heres what I did...
I created fullKeyboard.lua containing the following:
And another file call cl_fullKeyboard.lua:Code:concommand.Add( "e2keystate", function( player, command ) print("I got here") end) local RP = RecipientFilter() RP:AddAllPlayers() registerFunction("queryClient", "", "", function() umsg.Start("runMe", RP) umsg.End() // SendUserMessage("runMe") end)
The result, nothing happens at all when firing an expression with "queryClient()" in it. I see no messages on the client or server now. I must have done something wrong...Code:usermessage.Hook("runMe", function() Msg("Client received message") RunConsoleCommand("e2keystate") end)
So no one has any idea why this doesn't work? The example I included where the clientside and serverside were both in the same file used to work. I used input support version 1.1 about a year ago. I took a break and when i came back input support was broken. Version 1.2 works mostly the same. If it's a usermessage specific issue, it must be with e2 extensions only.
Edit: Think i just figured out whats wrong. Splitting the files into client/server is necessary along with sending the client file to the client with AddCSLuaFile. After doing this, client side stuff started working. Something must have changed to cause this cuz it wasn't always necessary to split the files like this.
Last edited by phreak314; 01-30-2010 at 08:35 PM.
Bookmarks