Discord Moderators Pirulax Posted March 6, 2017 Discord Moderators Posted March 6, 2017 (edited) Hello guys!How can i use the variables bannedBy, and accountID outside of this code block? local bannedBy local accountID for _, row in ipairs(query) local bannedBy = row["bannedBy"] local accountID = row["accountID"] end Edited March 6, 2017 by Pirulax
Bonsai Posted March 6, 2017 Posted March 6, 2017 If you remove the "local" inside the loop, they will be available outside of the loop, because you defined them outside of the loop too. But since this is a loop, the two variables will only have the value of the last row, everything before that is lost.
Discord Moderators Pirulax Posted March 6, 2017 Author Discord Moderators Posted March 6, 2017 only the last row? How u think that?
Addlibs Posted March 6, 2017 Posted March 6, 2017 (edited) What @Bonsai recommended was removing 'local' on both lines within the loop. And he is right about the last row thing. What the code will do if you remove the 'local' is change the same variables over and over again, and what will be on these variables after the last loop, is what was set on the last iteration: the data from the last row of the query table. Edited March 6, 2017 by MrTasty
Discord Moderators Pirulax Posted March 6, 2017 Author Discord Moderators Posted March 6, 2017 Okey, thanks
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