Code returns random numbers instead of actual values

Making a gamemode in which buttons on the map allow players to buy stuff, using the buttons’ keyvalues. But instead of subtracting the cost of the button from the player’s money, it replaces the cost with a random number.

Two buttons have the keyvalues ‘cost’ and ‘500’. One’s value is replaced by 255 and the other is replaced by 338.

[lua]
function GM:EntityKeyValue(ent,key,value)
if (ent:GetClass() == “func_door” or “func_button” or “func_button_rot” or “func_door_rotating”) and (key == “cost” or “Cost”) then
ent.cost = tonumber(value)
end
end

function usemapitem(ply,ent)
if IsValid(ent) then
if (ent:GetClass() == “func_door” or “func_button” or “func_button_rot” or “func_door_rotating”) and ply.points >= ent.cost then
timer.Create(“activate”…ent:EntIndex(),0.3,1, function()
ply:TakePoints(tonumber(ent.cost))
ply:ChatPrint(""…ent.cost)
ply:SetNWInt(“kpoints”,ply.points)
end)
return true
else return false
end
end
end
hook.Add( “PlayerUse”, “some_unique_name”, usemapitem )
[/lua]

Do

print(ent, ent.cost, tonumber(value) ) in your GM:EntityKeyValue and post results.

[lua]
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] -1 -1
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] nil nil
Entity [0][worldspawn] 30 30
Entity [0][worldspawn] 1 1
Entity [10][info_player_start] nil nil
Entity [10][info_player_start] 0 0
Entity [10][info_player_start] nil nil
Entity [10][info_player_start] nil nil
Entity [10][info_player_start] 214 214
Entity [11][prop_physics] nil nil
Entity [11][prop_physics] 526 526
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] nil nil
Entity [11][prop_physics] 255 255
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0.1 0.1
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 1 1
Entity [11][prop_physics] nil nil
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 1 1
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 1 1
Entity [11][prop_physics] -1 -1
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] 0 0
Entity [11][prop_physics] nil nil
Entity [11][prop_physics] nil nil
Entity [11][prop_physics] 216 216
Entity [12][func_door] nil nil
Entity [12][func_door] 4 4
Entity [12][func_door] 0 0
Entity [12][func_door] 100 100
Entity [12][func_door] 0 0
Entity [12][func_door] 256 256
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] nil nil
Entity [12][func_door] 255 255
Entity [12][func_door] nil nil
Entity [12][func_door] nil nil
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 0 0
Entity [12][func_door] 100 100
Entity [12][func_door] nil nil
Entity [12][func_door] 245 245
Entity [13][func_button] nil nil
Entity [13][func_button] 3 3
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 5 5
Entity [13][func_button] 1024 1024
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] nil nil
Entity [13][func_button] 255 255
Entity [13][func_button] nil nil
Entity [13][func_button] nil nil
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 0 0
Entity [13][func_button] 500 500
Entity [13][func_button] nil nil
Entity [13][func_button] 338 338
[/lua]


function GM:EntityKeyValue(ent,key,value)
	if (ent:GetClass() == "func_door" or "func_button" or "func_button_rot" or "func_door_rotating") and (key == "cost" or "Cost") then
		ent.cost = tonumber(value)
	end
end

Please read your code again.

ent:GetClass() == “func_door” or “func_button” or “func_button_rot” or “func_door_rotating” will always return true because string always equals to true.

if class is not equal to “func_door”, it will go ahead and see “func_button” as true.
Same goes for key == “cost” or "Cost"

Wouldn’t have figured that out for years. I forgot how picky lua’s syntax is. Thanks.