0

I'm making a script for Garry's Mod and it's almost complete but for some reason when ever I type in the new Cvar i made it won't change host_framerate. if anyone know what the problem is your a life saver.

local speedCvar = CreateClientConVar( "speedhack_enabled", 0, true, false )
local speedHackCvar = CreateClientConVar( "speedhack_enabled", "0", true, false )
local speedHack = SpeedHackCvar:GetString()
local speed = function()
    if (speedCvar:GetInt() == 1) then
        speedHack = SpeedHackCvar:GetString()
        RunConsoleCommand("host_framerate", speedHack)
    else
        speedHack = SpeedHackCvar:GetString()
        RunConsoleCommand("host_framerate " , speedHack)
    end
end
  • 1
    [Lua is a case-sensitive language](http://www.lua.org/manual/5.2/manual.html#3.1) – Tom Blodget Sep 13 '14 at 00:28
  • Try using an IDE that helps find this sort of (non-syntax) error. – Tom Blodget Sep 13 '14 at 00:29
  • So after taking a break and see your guyses comments i found that i had a capital S instead of a lower case s. Thanks to Tom Blodget for pointing that out. now i don't get the index global error but when i type "speedhack_enabled 1" it wont change the command "host_framerate". Do i need to add the # i want it in the line RunConsoleCommand("host_framerate 5 " , speedhack)??? – Bob Gravity Sep 13 '14 at 01:08
  • In `speedCvar` and `speedHackCvar`, you're defining the same cvar (`speedhack_enabled`) twice. You also define `speedhack` twice, both in and out of the `if` clause. – ASCIIThenANSI Apr 18 '15 at 20:15

1 Answers1

-1

Remove the local from first of each line (creation of your objects) to make your objects go globally across the lua. Your problem is that your functions are localized, which means they can only be accessed from the file/code block or chunk they're created in.

Oh and also you had a mistake on your code, which Is fixed (From reading comments on your post).

111WARLOCK111
  • 153
  • 1
  • 1
  • 9
  • Could you possibly write it out for me? im new to lua so it's kind of hard to understand where and what your telling me to do. – Bob Gravity Sep 13 '14 at 16:17
  • 1
    This advice seems to be specific to Garry's Mod. For Lua in general, it is not correct and goes against best practice. – Tom Blodget Sep 14 '14 at 01:50
  • Can someone help me? i need to fix this because it has been bugging me since yesterday. – Bob Gravity Sep 14 '14 at 03:07
  • @BobGravity Your original question has been resolved (and isn't all that useful for future visitors so I suggest deleting it). I think your new question needs a new title and focuses on Garry's Mod (which I'm not familiar with). Perhap 111WARLOCK11 will follow you to the new question. – Tom Blodget Sep 14 '14 at 15:51
  • @TomBlodget It's bad advice for Garry's Mod as well, generally. – Qix - MONICA WAS MISTREATED Sep 14 '14 at 20:25
  • @Qix The point is he just copied an old code and trying to make it work. From my readings, I think he's trying to access the convars on another file so basically making convars go global can make the other file work. – 111WARLOCK111 Sep 16 '14 at 13:56