Forum

> > CS2D > Scripts > why my script hive Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English why my script hive Error

12 replies
To the start Previous 1 Next To the start

old why my script hive Error

maninja
User Off Offline

Quote
Hi all I have a script lua a mistake that I do not know. Please help me

1
2
3
LUA ERROR: sys/lua/IF/sys/hooks.lua:337: attempt to index global 'havebal' (a nil value)
 -> sys/lua/IF/sys/hooks.lua:337: in function <sys/lua/IF/sys/hooks.lua:336>
 -> in Lua hook 'drop', params: 2, 358, 74, 0, 0, 0, 52, 13

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function rp_drop(id,iid,type,ain,a,mode,x,y)
	if havebal[id]==true then
		parse("strip "..id.." "..type)
		parse("spawnitem "..type.." "..x.." "..y)
		havebal[id]=false
		return 1
	end
	for k, v in ipairs(Addons) do
		if v.FHave[id]==1 then
			if v.wpn == type then
				gmsg2(id,"255000000","You can't drop your weapon!")
				return 1
			end
		end
	end
end

old Re: why my script hive Error

Masea
Super User Off Offline

Quote
So do that. You cannot declare a variable in a table that not yet exist.

By the way,
if havebal[id] == true then
and
if havebal[id] then
are totally the same statements, use the second one instead to keep your code a bit more clean.

old Re: why my script hive Error

Masea
Super User Off Offline

Quote
@user Rainoth: Although, it depends on what you get when one said: "exists".

x = true

x variable exists and is true and the both statement would be true.

x = false

x variable exists and is false and the both statement would be false.

local x

x variable exists and is undefined? The both statement would be false anyway.

As a result, I'd say they both are totally the same, even if they are not when it comes to "technically" saying.

@user Rainoth: I posted this comment just to make sure if you actually meant that you have seen other possibilities that these both statements cannot be matched to each other when you saying that.

old Re: why my script hive Error

Avo
User Off Offline

Quote
1) Declare global
havebal={}


or:

2) If it is some kind of a football script, maybe it should be
haveball
?

old Re: why my script hive Error

Rainoth
Moderator Off Offline

Quote
@user Masea: Yes I had in mind the usability of both. They do work like you mentioned but the one without comparison can also be used to check if variables exist (like say if a variable existed even if it wasn't a boolean).
Meaning although you can use both in this scenario, they are not technically the same because you can use one in a wider variety of cases.

@user maninja: Like we told you before, your 'havebal' variable doesn't exist.

You need to define it like so
1
haveball = {}
and then set it to true for a player when he's supposed to have it true.
From looking at the code, it seems like it should "simulate" dropping an item while preventing the actual drop of the item. I'm guessing it's to spawn an item with full ammo or something like that.

old Re: why my script hive Error

maninja
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function rp_drop(id,iid,type,ain,a,mode,x,y)
    haveball = {}
     if havebal[id]==true then
          parse("strip "..id.." "..type)
          parse("spawnitem "..type.." "..x.." "..y)
          havebal[id]=false
          return 1
     end
     for k, v in ipairs(Addons) do
          if v.FHave[id]==1 then
               if v.wpn == type then
                    gmsg2(id,"255000000","You can't drop your weapon!")
                    return 1
               end
          end
     end
end
@user Rainoth: you mean this ..

old Re: why my script hive Error

Avo
User Off Offline

Quote
More like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
havebal = {}

function rp_drop(id,iid,type,ain,a,mode,x,y)
     if havebal[id]==true then
          parse("strip "..id.." "..type)
          parse("spawnitem "..type.." "..x.." "..y)
          havebal[id]=false
          return 1
     end
     for k, v in ipairs(Addons) do
          if v.FHave[id]==1 then
               if v.wpn == type then
                    gmsg2(id,"255000000","You can't drop your weapon!")
                    return 1
               end
          end
     end
end
Global means that it is not declared inside any function (like rp_drop).

old Re: why my script hive Error

Quattro
GAME BANNED Off Offline

Quote
I bet this is the outcome
haveball = {}
for i = 1, 1000000 do
     local id = i
     if havebal[id] then
          msg('will we ever see this message? ;-;')
     end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview