Forum

> > CS2D > General > Attempt to perform arithmetic on field "?"
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Attempt to perform arithmetic on field "?"

2 replies
To the start Previous 1 Next To the start

old Attempt to perform arithmetic on field "?"

Dousea
User Off Offline

Quote
Hello,

Recently, I've a problem that I can't solve. I don't really know about math if the problem is related to math, so this may be a problem that can't be solved alone. This problem is very easy for you if you are smart enough. Let's look at the code which creates the problem first:
local tile_x, tile_y = getteamdomination (team, "x")[spawn_point] + between_tile_x, getteamdomination (team, "y")[spawn_point] + between_tile_y

This is the function associated with the code above:
local function getteamdomination (team, variable)
	if (team == 1) then
		return conquest.t.domination[variable]
	elseif (team == 2) then
		return conquest.ct.domination[variable]
	end
end

For the problem:
LUA ERROR: sys/lua/samples/conquest.lua:317: attempt to perform arithmetic on field '?' (a nil value)

The code above is in the different block. The function above works fine. I've tried to print the code above in the form of a string. It didn't help because the problem has been nil and the printed string made nil as well. To make you more understand about the other variable that connected to the source problem:
local team = player (id, "team")

local spawn_point = math.random (getteamdomination (team, "point"))
local between_tile_x, between_tile_y = math.random (-2, 2), math.random (-2, 2)

Do you understand the issue? Even the smallest problem I still don't know why it could have errors. I've explained everything you need to know in dealing with my problem. If you want more explanation, ask.

old Re: Attempt to perform arithmetic on field "?"

Starkkz
Moderator Off Offline

Quote
1
local tile_x, tile_y = getteamdomination (team, "x")[spawn_point] + between_tile_x, getteamdomination (team, "y")[spawn_point] + between_tile_y
This is the line 317, right? You could use more local variables to check which is a nil value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local team_domination_x = getteamdomination(team, "x")
local team_domination_y = getteamdomination(team, "y")

print("team_domination_x = "..tostring(team_domination_x))
print("team_domination_y = "..tostring(team_domination_y))
print("spawnpoint = "..tostring(spawnpoint))

team_domination_x = team_domination_x[spawnpoint]
team_domination_y = team_domination_y[spawnpoint]
print("team_domination_x = "..tostring(team_domination_x))
print("team_domination_y = "..tostring(team_domination_y))

print("between_tile_x = "..tostring(between_tile_x))
print("between_tile_x = "..tostring(between_tile_y))

local tile_x = team_domination_x + between_tile_x
local tile_y = team_domination_y + between_tile_y
print("tile_x = "..tostring(tile_x))
print("tile_x = "..tostring(tile_y))
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview