Forum

> > CS2D > Scripts > Lua question - Nil value error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua question - Nil value error

6 replies
To the start Previous 1 Next To the start

old Lua question - Nil value error

Infinite Rain
Reviewer Off Offline

Quote
Hello guys!
I got error in fallowing part of script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook("say","housefuncs")
function housefunc(id,text)
 for i=1,#house do
  if text=="!house_buy" then
   if btp(id,house[i].infox,house[i].infoy,house[i].infox,house[i].infoy,2) then
    if house[i].owner==nil then
     if player(id,"money")>=house[i].amount then
      house[i].owner=player(id,"usgn")
      msg2(id,"Gratz you purchase that house!")
     else
      msg2(id,"You dont have money to purchase that house!")
     end
    else
     msg2(id,"That house already buyed by someone!")
    end
   end
  end
 end
end

That error appears when i try to say SOMETHING (Any word lika Hi bye or gjsdgbjdfg anyways!)
Console dont told me where just say that:
Lua error attempt to call a nil value

Please help!

Thanks.
edited 1×, last 11.01.11 08:53:23 am

Admin/mod comment

Pushing/bumping is forbidden. Read the rules! /TKD

old Re: Lua question - Nil value error

DannyDeth
User Off Offline

Quote
You should not be writing Lua scripts if you cannot give infomation properly. Atempting to call a nil value means trying to read infomation from a variable that doesn't exsist. We need to see all your variable declorations, etc before we can tell you what is wrong. You should know this!

old Re: Lua question - Nil value error

Infinite Rain
Reviewer Off Offline

Quote
Okay here id full script (PLZ DNT FAKE IT!)

server.lua
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
function btp(id,sx,sy,ex,ey,mode)
   local prp
   if mode==1 then prp="" elseif mode==2 then prp="tile" end
   return (player(id,"exists") and player(id,prp.."x")>sx and player(id,prp.."x")<ex and player(id,prp.."y")>sy and player(id,prp.."y")<ey)
end

dofile("sys/lua/configs.lua")

function initArray(m)
	local array = {}
	for i = 1, m do
		array[i] = 0
	end
return array
end

oldx=initArray(32)
oldy=initArray(32)
timer=initArray(32)
buy=initArray(32)

addhook("minute","addtime")
function addtime()
	for i=1,#house do
		timer[i]=timer[i]-1
	end
end

addhook("move","housecheck")
function housecheck(id,x,y,mode)
	for i=1,#house do
		if btp(id,house[i].x1,house[i].y1,house[i].x2,house[i].y2,2) then
			if (house[i].owner==player(id,"usgn"))==false then
				msg2(id,"Its not your house!")
				parse("setpos "..id.." "..oldx[id].." "..oldy[id])
			elseif (house[i].owner==player(id,"usgn"))==true then
				msg2(id,"Welcome home!")
			end
		else
			oldx[id]=x
			oldy[id]=y
		end
		if btp(id,house[i].infox,house[i].infoy,house[i].infox,house[i].infoy,2) then
			buy[id]=1
			oldx[id]=x
			oldy[id]=y
		else
			buy[id]=0
			oldx[id]=x
			oldy[id]=y
		end
	end
end

addhook("say","housefuncs")
function housefunc(id,text)
	for i=1,#house do
		if (text=="!housebuy") then
			if buy[id]==1 then
				if house[i].owner==nil then
					if player(id,"money")>=house[i].amount then
						house[i].owner=player(id,"usgn")
						msg2(id,"Gratz you purchase that house!")
					else
						msg2(id,"You dont have money to purchase that house!")
					end
				else
					msg2(id,"That house already buyed by someone!")
				end
			end
		end
	end
end

configs.lua
1
2
3
4
5
6
7
8
9
10
11
12
--Houses
house={}

house[1]={}
house[1].x1=1
house[1].y1=1
house[1].x2=4
house[1].y2=4
house[1].infox=5
house[1].infoy=5
house[1].amount=100
house[1].owner=nil

Please help me somebody!

@TKD Soz for spaming!

old Re: Lua question - Nil value error

Flacko
User Off Offline

Quote
Sorry dude, Lua scripting is not for blind people

1
2
addhook("say","housefuncs")
function housefunc(id,text)

In case you didn't notice, THE NAME YOU GAVE TO ADDHOOK DOESN'T MATCH THE FUNCTION NAME.

old Re: Lua question - Nil value error

J4x
User Off Offline

Quote
Yeah flacko has reason...

> change this
1
2
addhook("say","housefuncs")
function housefunc(id,text)
>to this
1
2
addhook("say","housefuncs")
function housefuncs(id,text)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview