Jump to content

How to use a variable outside of for code block.


Pirulax

Recommended Posts

  • Discord Moderators

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 by Pirulax
Link to comment

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.

Link to comment

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 by MrTasty
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...