Forum

> > CS2D > Scripts > a nil value in a shop script
Forums overviewCS2D overview Scripts overviewLog in to reply

English a nil value in a shop script

6 replies
To the start Previous 1 Next To the start

old a nil value in a shop script

Mami Tomoe
User Off Offline

Quote
Yes I figured out that my name is my problem..

Hi, I'm trying to revive my old server but I've got some errors that I'm trying to fix and this is one of them.
Error:
Spoiler >

Script:
Spoiler >


Some stuff you should note: rp_money is declared
This is a shop script for hats and lottery tickets (2 menus)

pls
edited 1×, last 20.02.16 10:34:51 pm

old Re: a nil value in a shop script

zazz
User Off Offline

Quote
Replace the Lottery thing with this one:

1
2
3
4
["Buy Lottery Tickets"] = {
[1] = {price = 10000, itemid = 86, itemname = "a Bronze Ticket"},
[2] = {price = 25000, itemid = 54, itemname = "a Silver Ticket"},
[3] = {price = 50000, itemid = 53, itemname = "a Golden Ticket"}}

old Re: a nil value in a shop script

Cure Pikachu
User Off Offline

Quote
@user Ya_Bogalb: Then please refrain from answering.
@user zazz: No, look:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
purchases = {
	["Buy Hats"] = {
		{price = 500, path = "gfx/shop_clothes_and_guns/angel.png", itemname = "Angel Hat"},
		{price = 1000, path = "gfx/shop_clothes_and_guns/devil.png", itemname = "Devil Hat"},
		{price = 0, path = "gfx/nohat.png", itemname = "Remove Hat"}
	},
	["Buy Lottery Tickets"] = {
		{price = 10000, itemid = 86, itemname = "a Bronze Ticket"},
		{price = 25000, itemid = 54, itemname = "a Silver Ticket"},
		{price = 50000, itemid = 53, itemname = "a Golden Ticket"}
	},
	["Buy Extra Score"] = {
		{price = 25009999, score = 0},
		{price = 50009999, score = 0},
		{price = 10000999, score = 0}
	}
}
The ["Buy Lottery Tickets"] entry is in the purchases table and is not the last entry. Removing the comma at the end would make the problem worse.

@OP: Maybe
1
if k == t then
change it to
1
if k == t and (b > 0 and b < #v) then
TBH I am not really sure, just going by what the error message tells me.

old Re: a nil value in a shop script

Mami Tomoe
User Off Offline

Quote
@user Cure Pikachu:
1
2
3
4
5
LUA ERROR: sys/lua/autorun/shops.LUA:40: attempt to compare number with nil
 -> sys/lua/autorun/shops.LUA:40: in function 'menu_hook'
 -> [string "menu_hook(1, "Buy Lottery Tickets", nil)"]:1: in main chunk
 -> sys/lua/menufuncs/menufuncs.lua:98: in function <sys/lua/menufuncs/menufuncs.lua:73>
 -> in Lua hook 'menu', params: 1, 'Buy Lottery Tickets', 1

Seems like 'b' is a nil value
Found that out by adding:
1
2
3
4
print("The id is: "..id)
print("The k is: "..k)
print("The t is: "..t)
print("The b is: "..b)
and I got nil value error on the forth line ^
Which means b is not declared

Updated script (with debugging stuff)
Spoiler >

old Re: a nil value in a shop script

GeoB99
Moderator Off Offline

Quote
That's because...
1
if k == t and (b > 0 and b < #v) then
Where you were attempting to compare b with 0 and #v as numbers. Since b doesn't bring any value thus nil as you've guessed, you cannot simply make a comparison between a number and with something that has nothing. b must be declared with something or such. Try this:
1
if k == t and b == v.str then
Though I can't guarantee 100% it will work at the fullest.

old Re: a nil value in a shop script

EngiN33R
Moderator Off Offline

Quote
I don't understand. I copied and pasted the script you provided in your latest post ("with debugging stuff"), adding this at the end for debugging purposes:
1
2
rp_money = {}
rp_money[1] = 100000

I get no errors. After setpos'ing myself to 43|21 I get the menu, I press the Bronze Ticket button and I get this in the console:
1
2
3
4
5
The id is: 1
The k is: Buy Lottery Tickets
The t is: Buy Lottery Tickets
The b is: 1
[Server]: You bought a Bronze Ticket for 10000

b can't be undeclared since it's an argument passed by the cs2d lua hook menu hook, so unless you unset it manually it should always have a value. Check that there aren't any conflicts.

old Re: a nil value in a shop script

Mami Tomoe
User Off Offline

Quote
I fixed it somehow, I'm not sure how though here's what I did:

I removed some lua files that I don't remember adding to autorun folder and server.lua

I combined all the menu hooks

I did more stuff that I forgot about

Boom works

Thanks for the help though!
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview