Bad argument (Nil Value)
13 replies



27.02.12 12:45:21 am
Hello again everyone!
I'm getting the error
With this:
Timer that calls the function "timefuncI"
And here's the function:
What's wrong here? I think the problem is with the "id" value.
I'm getting the error
Code:
1
LUA ERROR: maps/SBV1.0.0.lua:79: Bad Argument #1 to 'msg2' (number expected, got nil)
With this:
Timer that calls the function "timefuncI"
Code:
1
timer(2700, "timefuncI")
And here's the function:
Code:
1
2
3
4
2
3
4
function timefuncI()
msg2(id, "©000255000Hello and welcome to our Test Subjects center.") <-- Line 79
msg2(id, "©000255000As you may have noted, you can now move in another way.")
end
msg2(id, "©000255000Hello and welcome to our Test Subjects center.") <-- Line 79
msg2(id, "©000255000As you may have noted, you can now move in another way.")
end
What's wrong here? I think the problem is with the "id" value.
You are right. You call the function with no parameters.
Got no fix for you atm. though, I'm not on a computer.
You should add parameters to your functions. Eg:
Do this for your _always and _hit functions too.
Got no fix for you atm. though, I'm not on a computer.
You should add parameters to your functions. Eg:
Code:
1
function timefuncI(id)
Do this for your _always and _hit functions too.
edited 1×, last 27.02.12 01:34:42 am
Change this
to this
I'm not good explaining lua, I can just tell the "id" was an undefined variable or something like that...
Code:
1
2
3
4
2
3
4
function timefuncI()
msg2(id,"©000255000Hello and welcome to our Test Subjects center.")
msg2(id,"©000255000As you may have noted, you can now move in another way.")
end
msg2(id,"©000255000Hello and welcome to our Test Subjects center.")
msg2(id,"©000255000As you may have noted, you can now move in another way.")
end
to this
Code:
1
2
3
4
5
6
2
3
4
5
6
function timefuncI(i)
for i=1,32 do
msg2(i,"©000255000Hello and welcome to our Test Subjects center.")
msg2(i,"©000255000As you may have noted, you can now move in another way.")
end
end
for i=1,32 do
msg2(i,"©000255000Hello and welcome to our Test Subjects center.")
msg2(i,"©000255000As you may have noted, you can now move in another way.")
end
end
I'm not good explaining lua, I can just tell the "id" was an undefined variable or something like that...
@
J4x Thank you! This worked. I now also kinda know how the "for...do" works. Thanks.

I think you also have to add:
under timefuncI()
Code:
1
if not player(i,"exists") then return end
under timefuncI()
Cs2d tibia tutorial ================ My new CS2D RPG Project Video

I think you also have to add:
under timefuncI()
Code:
1
if not player(i,"exists") then return end
under timefuncI()
Yep, i agree.
Without it, the code is kind of sketchy.
is this
you don't especifict the id , you in the function timefunc don't type a value , but the msg2 , have a value , is "id"
, ok copy , and paste , and it finish
sorry for my bad english
Code:
1
timer(2700, "timefuncI",id)
Code:
1
2
3
4
5
2
3
4
5
function timefuncI(id) -- this now have a value "id"
msg2(id, "©000255000Hello and welcome to our Test Subjects center.") -- here uses the value "id"
msg2(id, "©000255000As you may have noted, you can now move in another way.") -- here uses the value "id"
end
end
msg2(id, "©000255000Hello and welcome to our Test Subjects center.") -- here uses the value "id"
msg2(id, "©000255000As you may have noted, you can now move in another way.") -- here uses the value "id"
end
end
you don't especifict the id , you in the function timefunc don't type a value , but the msg2 , have a value , is "id"
, ok copy , and paste , and it finish
sorry for my bad english


Change this
to this
I'm not good explaining lua, I can just tell the "id" was an undefined variable or something like that...
Code:
1
2
3
4
2
3
4
function timefuncI()
msg2(id,"©000255000Hello and welcome to our Test Subjects center.")
msg2(id,"©000255000As you may have noted, you can now move in another way.")
end
msg2(id,"©000255000Hello and welcome to our Test Subjects center.")
msg2(id,"©000255000As you may have noted, you can now move in another way.")
end
to this
Code:
1
2
3
4
5
6
2
3
4
5
6
function timefuncI(i)
for i=1,32 do
msg2(i,"©000255000Hello and welcome to our Test Subjects center.")
msg2(i,"©000255000As you may have noted, you can now move in another way.")
end
end
for i=1,32 do
msg2(i,"©000255000Hello and welcome to our Test Subjects center.")
msg2(i,"©000255000As you may have noted, you can now move in another way.")
end
end
I'm not good explaining lua, I can just tell the "id" was an undefined variable or something like that...
Remember, for efficient scripting - never, EVER get players as
Code:
1
for i=1,32 do
Use this construction instead:
Code:
1
for _,i in pairs(player(0,"table")) do
It iterates through every value in the player table thus eliminating any possibility of non-existing players, as well as improving the efficiency.
I code, therefore I exist.
Why can't you just use msg function except of msg2 with annoying cycle?
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
By the way, Pwnisher's code is incorrect, now that I think about it. The for loop should be outside the function - if you even need to iterate through the players, because at the moment the function argument does nothing since it's overrided by the inner loop.
I code, therefore I exist.



