Forum

> > CS2D > Scripts > Lua question - Table
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua question - Table

5 replies
To the start Previous 1 Next To the start

old Lua question - Table

Infinite Rain
Reviewer Off Offline

Quote
look at my code:
1
2
3
weaponshop[1]={x1=11,y1=5,x2=11,y2=6,npcpath="gfx/skilllife/npc3.png",npcposx=18,npcposy=3,npcrot=-90}
weaponshop[1]={item_id[1]=32,item_name[1]="M4a1",item_cost[1]=300}
weaponshop[1]={item_id[2]=45,item_name[2]="Laser",item_cost[2]=4500}

Error:

1
LUA ERROR at line 2 '}' expected near '='
WTF everything must work well pllz help me

old Re: Lua question - Table

DannyDeth
User Off Offline

Quote
It's probably code elsewhere, these seem fine to me
or you might be missing a comma somewhere which happens to cause this error.

old Re: Lua question - Table

Roni
User Off Offline

Quote
at which point did you create the tables "iteam_id", "item_name", "item_cost" ?
also im not sure if you can difine them like that in a table
try this
weaponshop={}
weaponshop[1]={}
weaponshop[1].item_id={*id1*,...}
weaponshop[1].item_cost={*cost1*,...}
weaponshop[1].item_name={*name1*,...}

old Re: Lua question - Table

Lee
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
weaponshop = {}
weaponshop[1] = {item_id=32,item_name="M4A1",item_cost=300}
...

-- To use again

local m4a1 = weaponshop[1]
print("You bought a "..m4a1.item_name)

PS: You can access all of these weapon information from within CS2D, so you can just rehash the item_cost based on wpn id rather than complicating the matter further.

Also, never post in all caps
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview