• lua_run entity not working
    9 replies, posted
Hello there, I am creating a gmod gamemode that has a lua_run entity on it's map that is called by math_counter. The entity is simply calling a function in my server-side lua files without arguments. However, I can fire the function normally via console [lua_run first_alert() ], but the entity is having problems with it. [ERROR] gamemodes/base/entities/entities/lua_run.lua:41: bad argument #1 to 'RunString' (string expected, got nil)   1. RunString - [C]:-1    2. RunCode - gamemodes/base/entities/entities/lua_run.lua:41     3. unknown - gamemodes/base/entities/entities/lua_run.lua:49 This is what it says after firing it with RunCode output. Any info/help on why is that happening? It may be simple but I'm really confused right now. https://files.facepunch.com/forum/upload/174532/0cf1af1c-14d5-4e92-a2f3-ccc743a448b2/hammer.PNG Thanks.
RunString( WHATEVER IS HERE IS WRONG, string identifier="RunString", boolean handleError=true )--On line 41 of lua_run.lua RunString
So you are saying that calling a function is wrong within the lua_run entity ? I believe it worked for me in the past, but most importantly, it does work in the console. Even trying to call the most simple function with print command does not seem to work.
It might just be as simple as the wrong syntax. Can you provide the lua code?
util.AddNetworkString( "alert_one" ) function first_alert() for k,v in pairs(player.GetAll()) do  v:ConCommand("play basebuild/achievement.wav") net.Start("alert_one") net.Send(v) end end This is the function that is being called. Even a simple function as function test() print("test") end doesn't work.
I don't see 'RunString' in the code you provided. Also util.AddNetworkString( "alert_one" ) is serverside, are you sure you have the right network string? Finally when testing 'print' are you just looking at the screen or did you check your console as well?
The key should be "Code" with a capital C, not "code". It's a bit silly, but that's how it is. Creating a lua_run entity in Hammer does create the Code key by default, so I guess you typed it in yourself somehow or are not using the FGD shipped with GMod?
The 'RunString' command is executed via the entity, so where should I put it in my code ? However, when testing, I saw some strange behaviour. Yes, I checked my console when using the test function and it worked perfectly with lua_run command but again without succes with the entity. I changed my test function to function test() RunString(first_alert() ) end and now it throws an error, but still executes the function as normal. [ERROR] gamemodes/basebuild/gamemode/init.lua:405: bad argument #1 to 'RunString' (string expected, got no value) All this is in init.lua , so it's server-side.
I think the reason it's not doing anything with the Entity is because you don't have a trigger for the code to be activated. For example if I just put function test() print("test") end it wouldn't do anything unless I did the run lua command for it, OR made a change to the file and saved it. However there are a number of ways you can trigger it. You could trigger it with a keypress, you could trigger it with a player death, you could trigger it with a custom command, etc. etc. As for the RunString... the error is displaying correctly for that one because it's directly referencing 'RunString' on line 405 but this time it's in the init.lua file instead of your lua_run.lua
Well, the entity itself is triggered by math_counter or by me when testing using ent_fire. It's ofc fired with 'RunCode' output.
Sorry, you need to Log In to post a reply to this thread.