1.Learn about scoping (global and local)
2.To random some value use proper function (built in rand in squirrel)
3.table_giveitems isn't table, it's array, in squirrel there is a slightly diffrerence between those two.
-Table: you can index table as you want, also you don't have insert numeric indexes in proper order (from 0 to x). To declare a table, you simply writing something like this: global_table <- {} or local local_table = {}
-Array: you are using methods, to manage array, like push, pop, etc. Array MUST BE indexed from 0 to x, and to add new value as last in the array, you simply using push method, read more in reference:
4.Don't use [] in array values, you have to write them without it, because there aren't indexes of table.
https://developer.electricimp.com/squirrel/array
Forgive me for my grammar mistakes, if i made any.
2.To random some value use proper function (built in rand in squirrel)
3.table_giveitems isn't table, it's array, in squirrel there is a slightly diffrerence between those two.
-Table: you can index table as you want, also you don't have insert numeric indexes in proper order (from 0 to x). To declare a table, you simply writing something like this: global_table <- {} or local local_table = {}
-Array: you are using methods, to manage array, like push, pop, etc. Array MUST BE indexed from 0 to x, and to add new value as last in the array, you simply using push method, read more in reference:
4.Don't use [] in array values, you have to write them without it, because there aren't indexes of table.
https://developer.electricimp.com/squirrel/array
Squirrel Script
- local items =
- [
- "ITMI_GOLD",
- "ITFO_APPLE",
- "ITFO_MILK",
- "ITFO_BEER", // this comma is optional
- ]
-
- addEventHandler("onPlayerJoin",function(pid)
- { // below code will be executed when player join to the server
- local item = rand() % items.len()
-
- giveItem(pid, Items.id(item), 1)
- })
Forgive me for my grammar mistakes, if i made any.