Forum

> > CS2D > Scripts > Object exists error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Object exists error

30 replies
Page
To the start Previous 1 2 Next To the start

old Re: Object exists error

Accurator
User Off Offline

Quote
Still the same error, on another line that is practically the same...

Error: LUA ERROR (ai_update_living): bots/includes/build.lua:31: attempt to perform arithmetic on global 'healthpercent' (a nil value)

Line 31:
1
elseif object(id,"health")<healthpercent*50 then

Code >

old Re: Object exists error

Starkkz
Moderator Off Offline

Quote
Line 17, add healthpercent as one of the returned variables from the previous function.
1
(...), healthpercent = building_properties (...)
Note that you still haven't changed id to oid
edited 1×, last 17.04.14 05:05:20 pm

old Re: Object exists error

Accurator
User Off Offline

Quote
Changed that... New error: LUA ERROR (ai_update_living): bots/includes/build.lua:31: attempt to perform arithmetic on local 'healthpercent' (a nil value)

Same kind of line.

I only changed this...

1
local maxhealth, repairable, upgradable, healthpercent = building_properties(id)

About id and oid:
1
2
if player(id,"team")==1 then
	local id = objectat(x,y)
AKA: It defines the object's ID after the player's ID now

old Re: Object exists error

Starkkz
Moderator Off Offline

Quote
On line 191, change the three lines to
1
healthpercent = maxhealth and maxhealth/100 or 0

old Re: Object exists error

Accurator
User Off Offline

Quote
I take it you meant line 192?

191:
1
if maxhealth then

192:
1
healthpercent=maxhealth/100

Changed the last three lines:
1
2
3
healthpercent=maxhealth and maxhealth/100 or 0
return maxhealth, repairable, upgradable, healthpercent
end

old Re: Object exists error

Starkkz
Moderator Off Offline

Quote
I meant 191 to 193. Also, I noticed that line 124 is useless because it's replacing the id variable given in the function parameters.

old Re: Object exists error

Accurator
User Off Offline

Quote
They WERE line 191 to 193. Now they're 190 to 192, because I removed line 124.

...And it's still not working. No errors.
edited 2×, last 17.04.14 09:07:33 pm

old Re: Object exists error

Dousea
User Off Offline

Quote
@user Accurator: Enough with the healthpercent thingy! This is too complicated for you and also waist your time. Just do the normal way like if building's health value less than the max health then. Also don't create any other function to build in your code, it is too inefficient. You could follow code below for your code or replace yours with it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function fai_build (id)
	if (playerweapons (id, 74)) then
		ai_selectweapon (id, 74)
		
		local closeobject = closeobjects (player (id, "x"), player (id, "y"), 560)
		
		if (#closeobject > 0) then
			for key, self in pairs (closeobject) do
				if (ai_freeline (id, object (self, "x"), object (self, "y"))) then
					local maxhealth = fai_building_maxhealth (self)
					
					if (object (self, "health") < maxhealth) then
						if (ai_goto (id, object (self, "x"), object (self, "y")) == 1) then
							ai_attack (id)
						end
					else
						table.remove (closeobject, key)
					end
				
					if (object (self, "health") >= maxhealth) then
						if (object (self, "type") == 3 or object (self, "type") == 4 or object (self, "type") == 9 or object (self, "type") == 8 or object (self, "type") == 11) then
							ai_attack (id)
						else
							table.remove (closeobject, key)
						end
					end
				end
			end
		else
			local money = player (id, "money")
			local tilex, tiley = (player (id, "tilex") + math.random (-1, 1)), (player (id, "tiley") + math.random (-1, 1))
			local function checktile (tile, value)
				if (tile ~= player (id, value)) then
					return tile
				else
					checktile ((player (id, value) + math.random (-1, 1)), value)
				end
			end
			
			tilex = checktile (tilex, "tilex")
			tiley = checktile (tiley, "tiley")
			
			if (money >= 5000) then
				local build = math.random (0, 5)
				
				if (build == 0) then
					ai_build (id, 6, tilex, tiley)
				elseif (build == 1) then
					ai_build (id, 7, tilex, tiley)
				elseif (build == 2) then
					ai_build (id, 8, tilex, tiley)
				elseif (build == 3) then
					ai_build (id, 13, tilex, tiley)
				else
					ai_build (id, 14, tilex, tiley)
				end
			else
				local build = math.random (0, 1)
				
				if (build == 0) then
					ai_build (id, 7, tilex, tiley)
				else
					ai_build (id, 14, tilex, tiley)
				end
			end
		end
	end
end

function fai_building_maxhealth (oid)
	local maxhealth = {150, 300, 500, 1000, 2000, 1000, 1000, 500, 1000, 100, 750, 1000, 500, 500, 1500}
	
	if (object (oid, "type") > 0 and object (oid, "type") < 16) then
		return maxhealth[object (oid, "type")]
	end
	
	return 0
end

old Re: Object exists error

Accurator
User Off Offline

Quote
oid doesn't help. The script no longer checks the health value. Also, I made another function, building_angle(id), so the bots would actually hit the buildings, but it only gives me errors. Now I get the error: LUA ERROR (ai_update_living): bots/includes/build.lua:212: attempt to perform arithmetic on local 'px' (a nil value)
I got this error after changing building_angle(id) to function building_angle(id,x,y,px,py), because it didnt seem to know the x, y, px and py values.

Code >
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview