• Progress Bar Help!!!
    6 replies, posted
Hey :) Ive been having problems with making a progress bar for the players exp ( the rank name by itself isnt to cool to look at ) Ive check and tried making a progress bar for it. For some reason i cant seem to figure the problem. One being idk what the ERROR means. Two is there is no red ( color i set it to ) on the bar. Ill provide my code and the ERROR. [code] function TestHUD() local ply = LocalPlayer() if ( !IsValid( LocalPlayer( ) ) ) then return; end local XP = ply:GetBhopRank() draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 )) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 15, Color( 220, 108, 108, 255 ) ) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 5, Color( 255, 255, 255, 40 ) ) end hook.Add( "HUDPaint", "TestHUD", TestHUD) [/code] Code [code] [ERROR] lua/includes/extensions/math.lua:46: attempt to compare string with number 1. Clamp - lua/includes/extensions/math.lua:46 2. fn - gamemodes/bhop/gamemode/bhop_hud.lua:348 3. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [/code] ERROR BTW the bar DOES work with HP and it goes down when i take damage :) Any help will be greatly appreciated :)
GetBhopRank probably returns a string / name instead of a number. If it returns a "number", it is in the form of a string ( not formatted correctly in that function ) so you could tonumber( ) it, or ensure the GetBhopRank returns a number, not a string.
-snip-
[QUOTE=Acecool;45741783]GetBhopRank probably returns a string / name instead of a number. If it returns a "number", it is in the form of a string ( not formatted correctly in that function ) so you could tonumber( ) it, or ensure the GetBhopRank returns a number, not a string.[/QUOTE] All right haha thankfully i understood :) Ill give it a try and post back if any problems emerge :) Thanks Acecool [editline]19th August 2014[/editline] [QUOTE=bluebull107;45741803]Im still mad at you for this atrocity... [url]http://facepunch.com/showthread.php?t=1416146&p=45634258&viewfull=1#post45634258[/url][/QUOTE] Then why waste your time commenting about it ? Its not going to help it. The past is the past. Living in the past will get you no where in life :( [editline]19th August 2014[/editline] [QUOTE=Acecool;45741783]GetBhopRank probably returns a string / name instead of a number. If it returns a "number", it is in the form of a string ( not formatted correctly in that function ) so you could tonumber( ) it, or ensure the GetBhopRank returns a number, not a string.[/QUOTE] Ok i did research and found this [url]http://www.lua.org/pil/2.4.html[/url] its saying that i have to create a new string. Is that correct? [editline]19th August 2014[/editline] Ok i tried this and it said on Console What i made it say if the value was nil. Tho the error is still present. Lol i am dumb when it comes to new things. Can you help me with telling me what is wrong with it. (dont give me the right code: No SpoonFeed ) [code] function TestHUD() local ply = LocalPlayer() if ( !IsValid( LocalPlayer( ) ) ) then return; end local XP = ply:GetBhopRank() n = tonumber( XP ) if n == nil then print ( "No Rank Value" ) end draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 )) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 15, Color( 220, 108, 108, 255 ) ) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 5, Color( 255, 255, 255, 40 ) ) end hook.Add( "HUDPaint", "TestHUD", TestHUD) hook.Add( "PlayerSay", "myCommand", myCommand ) [/code]
[QUOTE=Vizik;45741746]Hey :) Ive been having problems with making a progress bar for the players exp ( the rank name by itself isnt to cool to look at ) Ive check and tried making a progress bar for it. For some reason i cant seem to figure the problem. One being idk what the ERROR means. Two is there is no red ( color i set it to ) on the bar. Ill provide my code and the ERROR. [code] function TestHUD() local ply = LocalPlayer() if ( !IsValid( LocalPlayer( ) ) ) then return; end local XP = ply:GetBhopRank() draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 )) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 15, Color( 220, 108, 108, 255 ) ) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( XP, 0, 500 )*2, 5, Color( 255, 255, 255, 40 ) ) end hook.Add( "HUDPaint", "TestHUD", TestHUD) [/code] Code [code] [ERROR] lua/includes/extensions/math.lua:46: attempt to compare string with number 1. Clamp - lua/includes/extensions/math.lua:46 2. fn - gamemodes/bhop/gamemode/bhop_hud.lua:348 3. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [/code] ERROR BTW the bar DOES work with HP and it goes down when i take damage :) Any help will be greatly appreciated :)[/QUOTE] I'm not 100% sure, but doesn't ply:GetBhopRank( ) return their rank as text? "Casual", "Usual" etc? If I'm wrong and it does return a number as a string, you should be able to just do. local XP = tonumber( ply:GetBhopRank( ) ) Just to double check, put - print( ply:GetBhopRank( ) ) to make sure it's not returning "[Casual]" etc.. ( This is assuming you're running Ilya's bhop gamemode. ) I can check the gamemode later on today for you if you want.
[QUOTE=Minteh Fresh;45742448]I'm not 100% sure, but doesn't ply:GetBhopRank( ) return their rank as text? "Casual", "Usual" etc? [/QUOTE] Yes and thanks ill try it out :)
[QUOTE=Minteh Fresh;45742448]I'm not 100% sure, but doesn't ply:GetBhopRank( ) return their rank as text? "Casual", "Usual" etc? If I'm wrong and it does return a number as a string, you should be able to just do. local XP = tonumber( ply:GetBhopRank( ) ) Just to double check, put - print( ply:GetBhopRank( ) ) to make sure it's not returning "[Casual]" etc.. ( This is assuming you're running Ilya's bhop gamemode. ) I can check the gamemode later on today for you if you want.[/QUOTE] Hey yea it showed in the Command my level "Newbie" in console and it want add bar and the error is still also the same :(
Sorry, you need to Log In to post a reply to this thread.