Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Syntax Questing and Tables?

Asked by 8 years ago

How would I find if a string matches a value in a table, while also seeing what tuple it is? (I believe that's the correct term. What I mean is it's 'sequence' in the table, I guess.)

Why I ask this? I'm working on a little code redemption GUI, and I need a value to be removed from a table when the player redeems a value in the table, so they can't redeem it again and again and again.

0
This isn't very constructive, could you try to atleast try and script it. Post your script here and I will help you. User#5978 25 — 8y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

I think the term you're looking for is 'index'. A tuple is a variable-number of, well, variables. Typically upvalues for functions.

To actually answer your question, use a for loop:

local playerCodes = {'124525', 'bonanza', '125astdg'}
local textEntered = '124525'
for index, value in ipairs(playerCodes) do
    if value == textEntered then
        redeem(value) --Or however you handling redeeming a specific code.
        table.remove(playerCodes, index)
    end
end

There are some problems that might arise by using this method, but they're all edge case and if you don't know how to do this to begin with, I doubt you'd write code that would cause those bugs.

In any case, if you have bugged code, definitely ask about it here.

Ad

Answer this question