iPanda Posted February 11, 2014 Share Posted February 11, 2014 I create bots. Not to write a lot of code, I took the variable "i", but for some reason does not work. The following error occurred. local sniper = {} addEventHandler("onResourceStart", resourceRoot, function() local sniper[1] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[2] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[3] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[4] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) for i=1,4 do setElementHealth( sniper[i], 100 ) end end) Link to comment
csiguusz Posted February 11, 2014 Share Posted February 11, 2014 Table values can't be local. It's enough if you define the table as local. Link to comment
iPanda Posted February 11, 2014 Author Share Posted February 11, 2014 Table values can't be local. It's enough if you define the table as local. Thank you for help. But now there is a new bug. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 Not tested but you did the for statement wrong i believe. sniper = {} addEventHandler("onResourceStart", resourceRoot, function() local sniper[1] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[2] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[3] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[4] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) for _,data in ipairs(sniper) do setElementHealth( data, 100 ) end end) Link to comment
Moderators IIYAMA Posted February 11, 2014 Moderators Share Posted February 11, 2014 What is wrong? local sniper = {} addEventHandler("onResourceStart", resourceRoot, function() local sniper[1] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[2] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[3] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) local sniper[4] = exports.slothbot:spawnBot( myX, myY, myZ, 0, 286, 0, 0, nil, 33, "guarding", true ) for _,data in ipairs(sniper) do setElementHealth( data, 100 ) end end) That's wrong... Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 I thought i removed the local's my bad, plus he already knew that he cant have local tables, sorry doe Link to comment
Moderators IIYAMA Posted February 12, 2014 Moderators Share Posted February 12, 2014 it can be defined with a local, but only at the table it self. local sniper = {} Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now