I'm trying to port a gamemode over from Gmod 12 to the current version. I've managed to make it show up in the game, but when I spawn I get stuck on this loading screen and then I get this error spamming in my console:
[CODE][ERROR] gamemodes/cider/gamemode/cl_init.lua617: attempt to index global 'cider' (a nil value)
1. unknown - gamemode/cider/gamemode/cl_init.lua617[/CODE]
Post the code
[QUOTE=Triple-X;41512795]Post the code[/QUOTE]
[CODE]--[[
Name: "cl_init.lua".
Product: "Cider (Roleplay)".
--]]
include("sh_init.lua");
include("core/scoreboard/scoreboard.lua");
-- Set some information for the gamemode.
GM.topTextGradient = {};
GM.variableQueue = {};
GM.ammoCount = {};
-- Add a usermessage to recieve a notification.
usermessage.Hook("cider_Notification", function(msg)
local message = msg:ReadString();
local class = msg:ReadShort();
-- The sound of the notification.
local sound = "ambient/water/drip2.wav";
-- Check the class of the message.
if (class == 1) then
sound = "buttons/button10.wav";
elseif (class == 2) then
sound = "buttons/button17.wav";
elseif (class == 3) then
sound = "buttons/bell1.wav";
elseif (class == 4) then
sound = "buttons/button15.wav";
end
-- Play the sound to the local player.
surface.PlaySound(sound);
-- Add the notification using Garry's system.
GAMEMODE:AddNotify(message, class, 10);
end);
-- Override the weapon pickup function.
function GM:HUDWeaponPickedUp(...) end;
-- Override the item pickup function.
function GM:HUDItemPickedUp(...) end;
-- Override the ammo pickup function.
function GM:HUDAmmoPickedUp(...) end;
-- Called when an entity is created.
function GM:OnEntityCreated(entity)
if (LocalPlayer() == entity) then
for k, v in pairs(self.variableQueue) do LocalPlayer()[k] = v; end;
end;
-- Call the base class function.
return self.BaseClass:OnEntityCreated(entity);
end;
-- Called when a player presses a bind.
function GM:PlayerBindPress(player, bind, press)
if ( !self.playerInitialized and string.find(bind, "+jump") ) then
RunConsoleCommand("retry");
end;
-- -- Check if they're trying to use a binded Cider command.
-- if ( string.find(bind, "cider ") or string.find(bind, "say /") ) then
-- if ( !player:GetNetworkedBool("cider_Donator") ) then
-- player:ChatPrint("Only Donators can use binded Cider commands!");
-- -- Return true because they cannot use the command.
-- return true;
-- end;
-- end;
-- Call the base class function.
return self.BaseClass:PlayerBindPress(player, bind, press);
end;
-- Check if the local player is using the camera.
function GM:IsUsingCamera()
if (ValidEntity( LocalPlayer():GetActiveWeapon() )
and LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera") then
return true;
else
return false;
end;
end;
-- Hook into when the server sends us a variable for the local player.
usermessage.Hook("cider._LocalPlayerVariable", function(message)
local class = message:ReadChar();
local key = message:ReadString();
-- Create the variable which we'll store our received variable in.
local variable = nil;
-- Check if we can get what class of variable it is.
if (class == CLASS_STRING) then
variable = message:ReadString();
elseif (class == CLASS_LONG) then
variable = message:ReadLong();
elseif (class == CLASS_SHORT) then
variable = message:ReadShort();
elseif (class == CLASS_BOOL) then
variable = message:ReadBool();
elseif (class == CLASS_VECTOR) then
variable = message:ReadVector();
elseif (class == CLASS_ENTITY) then
variable = message:ReadEntity();
elseif (class == CLASS_ANGLE) then
variable = message:ReadAngle();
elseif (class == CLASS_CHAR) then
variable = message:ReadChar();
elseif (class == CLASS_FLOAT) then
variable = message:ReadFloat();
end;
-- Check if the local player is a valid entity.
if ( ValidEntity( LocalPlayer() ) ) then
LocalPlayer()[key] = variable;
-- Set the variable queue variable to nil so that we don't overwrite it later on.
GAMEMODE.variableQueue[key] = nil;
else
GAMEMODE.variableQueue[key] = variable;
end;
end);
-- A function to override whether a HUD element should draw.
function GM:HUDShouldDraw(name)
if (!self.playerInitialized) then
if (name != "CHudGMod") then return false; end;
else
if (name == "CHudHealth" or name == "CHudBattery" or name == "CHudSuitPower"
or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then
return false;
end;
-- Return true if it's none of the others.
return true;
end;
-- Call the base class function.
return self.BaseClass:HUDShouldDraw(name);
end
-- A function to adjust the width of something by making it slightly more than the width of a text.
function GM:AdjustMaximumWidth(font, text, width, addition, extra)
surface.SetFont(font);
-- Get the width of the text.
local textWidth = surface.GetTextSize( tostring( string.Replace(text, "&", "U") ) ) + (extra or 0);
-- Check if the width of the text is greater than our current width.
if (textWidth > width) then width = textWidth + (addition or 0); end;
-- Return the new width.
return width;
end;
-- A function to draw a bar with a maximum and a variable.
function GM:DrawBar(font, x, y, width, height, color, text, maximum, variable, bar)
draw.RoundedBox( 2, x, y, width, height, Color(0, 0, 0, 200) );
draw.RoundedBox( 0, x + 2, y + 2, width - 4, height - 4, Color(25, 25, 25, 150) );
draw.RoundedBox( 0, x + 2, y + 2, math.Clamp( ( (width - 4) / maximum ) * variable, 0, width - 4 ), height - 4, color );
-- Set the font of the text to this one.
surface.SetFont(font);
-- Adjust the x and y positions so that they don't screw up.
x = math.floor( x + (width / 2) );
y = math.floor(y + 1);
-- Draw text on the bar.
draw.DrawText(text, font, x + 1, y + 1, Color(0, 0, 0, 255), 1);
draw.DrawText(text, font, x, y, Color(255, 255, 255, 255), 1);
-- Check if a bar table was specified.
if (bar) then bar.y = bar.y - (height + 4); end;
end;
-- Get the bouncing position of the screen's center.
function GM:GetScreenCenterBounce(bounce)
return ScrW() / 2, (ScrH() / 2) + 32 + ( math.sin( CurTime() ) * (bounce or 8) );
end;
-- Called when the target ID should be drawn.
function GM:HUDDrawTargetID()
if ( LocalPlayer():Alive() and !LocalPlayer():GetNetworkedBool("cider_KnockedOut") ) then
local trace = LocalPlayer():GetEyeTrace();
-- Set the distance that text will be completely faded to the same as the talk radius.
local fadeDistance = cider.configuration["Talk Radius"];
-- Check if we hit a valid entity.
if ( ValidEntity(trace.Entity) ) then
local class = trace.Entity:GetClass();
-- Check if the entity is a player.
if ( trace.Entity:IsPlayer() ) then
local alpha = math.Clamp(255 - ( (255 / fadeDistance) * ( LocalPlayer():GetPos():Distance( trace.Entity:GetPos() ) ) ), 0, 255);
-- Get the x and y position.
local x, y = self:GetScreenCenterBounce();
-- Draw the player's name.
y = self:DrawInformation(trace.Entity:Name(), "ChatFont", x, y, team.GetColor( trace.Entity:Team() ), alpha);
-- Check if the player is in a clan.
if (trace.Entity:GetNetworkedString("cider_Clan") != "") then
y = self:DrawInformation("Clan: "..trace.Entity:GetNetworkedString("cider_Clan"), "ChatFont", x, y, Color(255, 255, 255, 255), alpha);
end;
-- Draw the player's job.
y = self:DrawInformation("Job: "..trace.Entity:GetNetworkedString("cider_Job"), "ChatFont", x, y, Color(255, 255, 255, 255), alpha);
elseif ( ValidEntity( trace.Entity:GetNetworkedEntity("cider_Player") ) ) then
local player = trace.Entity:GetNetworkedEntity("cider_Player");
-- Check if the player is alive.
if ( player:Alive() and player != LocalPlayer() ) then
local alpha = math.Clamp(255 - ( (255 / fadeDistance) * ( LocalPlayer():GetPos():Distance( trace.Entity:GetPos() ) ) ), 0, 255);
-- Get the x and y position.
local x, y = self:GetScreenCenterBounce();
-- Draw the player's name.
y = self:DrawInformation(player:Name(), "ChatFont", x, y, team.GetColor( player:Team() ), alpha);
-- Check if the player is in a clan.
if (player:GetNetworkedString("cider_Clan") != "") then
y = self:DrawInformation("Clan: "..player:GetNetworkedString("cider_Clan"), "ChatFont", x, y,
bump
From what I can tell "cider" which would be a table, seen as it is used throughout the code, is nil because it was never defined.
Try adding [lua]cider = { }[/lua] right under the GM tables.
[QUOTE=McDunkable;41529885]From what I can tell "cider" which would be a table, seen as it is used throughout the code, is nil because it was never defined.
Try adding [lua]cider = { }[/lua] right under the GM tables.[/QUOTE]
You mean under here?
[lua]-- Set some information for the gamemode.
GM.topTextGradient = {};
GM.variableQueue = {};
GM.ammoCount = {};
cider = { }[/lua]
That's what I did and now the error no longer appears.
Now these ones are:
[lua][ERROR] gamemodes/cider/gamemode/cl_init.lua617: attempt to index field 'configuration' (a nil value)
1. unknown - gamemode/cider/gamemode/cl_init.lua617[/lua]
[CODE][ERROR] gamemodes/cider/gamemode/cl_init.lua617: attempt to call global 'ValidEntity' (a nil value)
1. IsUsingCamera - gamemodes/cider/gamemode/cl_init.lua:82
2. unknown - gamemode/cider/gamemode/cl_init.lua540[/CODE]
Change ValidEntity to IsValid.
[QUOTE=Bo98;41533478]Change ValidEntity to IsValid.[/QUOTE]
Another error bites the dust! :)
Now for the configuration error...
[QUOTE=Toulpaw;41533518]Another error bites the dust! :)
Now for the configuration error...[/QUOTE]
Yes.
[lua]IsValid( var )[/lua]
[QUOTE=MrGregsWorld;41533597]Yes.
[lua]IsValid( var )[/lua][/QUOTE]
Where does that go?
[QUOTE=Bo98;41533478]Change ValidEntity to IsValid.[/QUOTE]
I did. I changed every ValidEntity to IsValid.
bump again
Don't try to fix a gamemode if you don't know Lua and if you can't even read and understand a page that tells you how to fix most issues you'll come across: [url]https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/[/url]
All you're doing right now is pasting your errors in here, expecting us to fix this whole thing for you.
[QUOTE=Jocken300;41550988]Don't try to fix a gamemode if you don't know Lua and if you can't even read and understand a page that tells you how to fix most issues you'll come across: [url]https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/[/url]
All you're doing right now is pasting your errors in here, expecting us to fix this whole thing for you.[/QUOTE]
And how does that page tell me how to fix the nil-value configuration error?
I bet if that error gets fixed, the gamemode will work.
Also I already did some of the work geting it to show up in the game anyway, so you're not doing EVERYTHING for me. But then what's the point of Developer Discussion anyway?
In my opinion Jocken300 is right.
You had an error that was fixed by @McDunkable then for some reasons you didn't knew where it has to go after that you had 2 other errors and @Bo98 fixed one of them but you still didn't know where to place it. It's not like you had an error and they fixed it for you, you had multiple errors and you will still have. Just because you think that the configuration error is the last that doesn't mean it is.
So how Jocken said "Don't try to fix a gamemode if you don't know Lua" You will get other errors that you will post here and expect to be fixed. If you do that you won't learn Lua.
I also have problems with something right now but I am not posting it here because I am trying to figure it out by myself. I tried one day and I had no luck but I'll keep trying.
Actually I wasn't expecting help, but thankfully some people did. You don't get those kind of people on the internet often.
And so what if I don't know LUA? Fixing the errors will help me to learn what to correct in a script.
Why don't you just tell me how to fix the configuration error and see if you're right? No other error is appearing in the console when I start up the gamemode.
And good luck trying to solve your problems without asking for help. It will take ages and you will most likely give up. I would have gotten nowhere if it hadn't been for Bo98 and McDunkable.
Hear me out, dude. Someone's selling this rare gamemode, updated for Gmod 13, for £60 ($90). I'm simply doing a favor for people who don't want to spend a ridiculous amount of money on a gamemode.
I am not saying that you are not doing a good thing for others but if you want to learn lua don't try with fixing game modes. Start with something more simple. And just to know I tried a few times to post something here when I needed help but nobody helped me so what is the point making a thread where nobody answers ?
[QUOTE=BoowmanTech;41555468]I am not saying that you are not doing a good thing for others but if you want to learn lua don't try with fixing game modes. Start with something more simple. And just to know I tried a few times to post something here when I needed help but nobody helped me so what is the point making a thread where nobody answers ?[/QUOTE]
Ah I see now.
I actually understand more now. Right now I'm correcting anything incompatible in the gamemode and fixing issues using the Why Your Scripts Are Now Broken page.
[I]"Don't learn to hack. Hack to learn".[/I]
Take a look in your sh_init on row 24 and 25.
Cider is defined in sh_init.lua:
[LUA]
-- Create the Cider table and the configuration table.
cider = {};
cider.configuration = {};
[/LUA]
make sure your includes are right.
[QUOTE=|Royal|;41557508]Take a look in your sh_init on row 24 and 25.
Cider is defined in sh_init.lua:
[LUA]
-- Create the Cider table and the configuration table.
cider = {};
cider.configuration = {};
[/LUA]
make sure your includes are right.[/QUOTE]
They look the same, so I guess it's right.
[QUOTE=Toulpaw;41557829]They look the same, so I guess it's right.[/QUOTE]
It is not alright.
Make sure your includes are working as they should. Because at the moment, You are creating an empty table, Where as in sh_init.lua, There may be (almost for a certainty) functions being defined in that table that defines game rules.
[QUOTE=dingusnin;41557943]It is not alright.
Make sure your includes are working as they should. Because at the moment, You are creating an empty table, Where as in sh_init.lua, There may be (almost for a certainty) functions being defined in that table that defines game rules.[/QUOTE]
Sorry if this is a dumb question, but how exactly do I make sure these "includes" are working correctly?
So far, I've corrected every text file according to this file: [url]https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit[/url]
A new error has arisen:
[CODE][ERROR] gamemodes/cider/gamemode/cl_init.lua540: function arguments expected near '.'
1. unknown - gamemode/cider/gamemode/cl_init.lua0[/CODE]
[CODE]Couldn't Load Init Script: 'cider/gamemode/cl_init.lua'[/CODE]
What did I told you ? If you fix an error another one might arrive.
[QUOTE=BoowmanTech;41563192]What did I told you ? If you fix an error another one might arrive.[/QUOTE]
Eh, I guess.
LUA file begins being analyzed for errors:
Found error -> Stop loading file
*Error fixed*
Sequentially starts analyzing file again -> Found the next error.
I feel like there's going to be a continuous loop of "Hey, that works, but this just came up" in this thread.
Why have you put a whole page of script for us to fix?
[QUOTE=PaellaPablo;41563552]LUA file begins being analyzed for errors:
Found error -> Stop loading file
*Error fixed*
Sequentially starts analyzing file again -> Found the next error.
I feel like there's going to be a continuous loop of "Hey, that works, but this just came up" in this thread.[/QUOTE]
To be honest, I feel that way too. But I know I'm getting closer. I've at least removed the console spam and I can see and move in the gamemode. Only the menu's aren't working.
If it helps, here's why I think it may not have worked.
Whenever I come across
[LUA]function PANEL:Paint()[/lua]
I replace it with
[LUA]function PANEL:Paint( w, h )[/lua]
I guess I need to provide a width and a height, right?
[QUOTE=mib999;41564858]Why have you put a whole page of script for us to fix?[/QUOTE]
Why not just tell me how to fix it?
Also, I'm not asking any of you to fix the gamemode for me. I'm asking you HOW to fix it so that I can implement whatever change you suggest into the code myself. I'm the one doing all the work, you're simply helping me like I asked. I spent 2-3 hours changing everything so it's compatible with GM13. So that means, every function PANEL:Paint() I come across gets changed to function PANEL:Paint ( w, h ). Every file.FindInLua or find. in general gets a "DATA" or "GAME" tag.
Should I post the script again with the changes applied?
Do you have anything inside the function PANEL:Paint() ?
[QUOTE=BoowmanTech;41567202]Do you have anything inside the function PANEL:Paint() ?[/QUOTE]
You mean this?
[lua]function PANEL:Paint( w, h)
draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 170, 170, 170, 255 ) )
surface.SetTexture( texGradient )
surface.SetDrawColor( 255, 255, 255, 50 )
surface.DrawTexturedRect( 0, 0, self:GetWide(), self:GetTall() )
// White Inner Box
draw.RoundedBox( 4, 4, self.Description.y - 4, self:GetWide() - 8, self:GetTall() - self.Description.y - 4, Color( 230, 230, 230, 200 ) )
surface.SetTexture( texGradient )
surface.SetDrawColor( 255, 255, 255, 50 )
surface.DrawTexturedRect( 4, self.Description.y - 4, self:GetWide() - 8, self:GetTall() - self.Description.y - 4 )
// Sub Header
draw.RoundedBox( 4, 5, self.Description.y - 3, self:GetWide() - 10, self.Description:GetTall() + 5, Color( 150, 200, 50, 200 ) )
surface.SetTexture( texGradient )
surface.SetDrawColor( 255, 255, 255, 50 )
surface.DrawTexturedRect( 4, self.Description.y - 4, self:GetWide() - 8, self.Description:GetTall() + 8 )
// Logo!
surface.SetTexture( texLogo )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.DrawTexturedRect( 0, 0, 128, 128 )
//draw.RoundedBox( 4, 10, self.Description.y + self.Description:GetTall() + 6, self:GetWide() - 20, 12, Color( 0, 0, 0, 50 ) )
end;
[/lua]
That's a code for the scoreboard.
Also I think I know what you mean by includes:
[lua]-- Include the configuration and enumeration files.
include("core/sh_configuration.lua");
include("core/sh_enumerations.lua");
[/lua]
This is what people are talking about?
Sorry, you need to Log In to post a reply to this thread.