Hi,
So I’ve got one last major thing to build for my Starsceptre game and it’s a cool Easter egg.
I’m looking to create a series of visual buttons and when each is clicked its value gets sent to a table or a string (not sure which I should do yet) and when you hit the submit button we assess your inputs against a predefined list of strings to see if one matches. Basically enter a code and see if you win something.
So say there are 6 buttons A,b,c,d,e,f,g plus a submit button
You could use any combination of those buttons and when you submit we check to see if it unlocks something.
So like you might enter a,a,c,f,g,a or any number of combos.
Should I use a blank table and add to each column (separated by a comma) or should I add to a string instead and assess ‘aacfga’ ?
I’ve not worked with strings yet, so I’m wondering What should I go for and am I on the right path?
I think it will be a 10 part string or table and we assess against that
Thanks
Major
Use a string. Then you can just compare one string to another.
Thanks @dave1707 - and it should be easy to append to a string or to set a limit on the number of characters.
Cheers, I’ll see how I get on
Much appreciated!
@Majormorgan Checking the string length and appending to it is easy.
function strAppend(v)
if #str<10 then
str=str..v
end
end
Awesome! Thank you @dave1707 !!!
@dave1707 that string append code is wonderful genius. Worked a dream and for displaying the results of the button press I reused the score code visualiser. Works a treat! Thank you
@Majormorgan After reading your question again, you can use a table along with what I showed you. You use a table of strings for your codes and compare your string against the table. In the code below, I just return match or no match, but you can do whatever your need.
function setup()
str="zzyyxxwwvv"
print(strComp(str))
str="zzrryyuwvv"
print(strComp(str))
end
function strComp(s)
codeTab={"abcdefghij","aabbccddee","zzyyxxwwvv","qwertyuiop","asdfghjklm"}
for z=1,#codeTab do
if s==codeTab[z] then
return("match")
end
end
return("no match")
end
thanks @dave1707 that code works a treat. I can’t wait to share how it’s used, although it’s going to be a secret Easter egg that I’m going to see if anyone finds
- it is cool though! Thanks again
So to remove the last character from the same string using a delete button I take it a new function would do something like
strlength=x
str=str..-v#
?
Thanks
Just found this by @Ignatz from another thread
s = string.sub(str,1,string.len(str)-1)
Thanks
@Majormorgan Instead of putting it in another string, you can put it in the same string like below.
str=string.sub(str,1,#str-1)
Awesome! Thank you @dave1707 !!!