Forum

> > CS2D > Scripts > Object exists error
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Object exists error

30 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Re: Object exists error

Accurator
User Off Offline

Zitieren
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 >

alt Re: Object exists error

Starkkz
Moderator Off Offline

Zitieren
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
1× editiert, zuletzt 17.04.14 17:05:20

alt Re: Object exists error

Accurator
User Off Offline

Zitieren
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

alt Re: Object exists error

Starkkz
Moderator Off Offline

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

alt Re: Object exists error

Accurator
User Off Offline

Zitieren
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

alt Re: Object exists error

Starkkz
Moderator Off Offline

Zitieren
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.

alt Re: Object exists error

Accurator
User Off Offline

Zitieren
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.
2× editiert, zuletzt 17.04.14 21:07:33

alt Re: Object exists error

Dousea
User Off Offline

Zitieren
@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

alt Re: Object exists error

Accurator
User Off Offline

Zitieren
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 >
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht