Reputation: 50
I am still working on the project that I made, the computer PIN cracking thing. And I want to make that when somebody click on a hint button, it will display the 1/4 of the password, the other will remains "*". But I can't even think of something to do!
I think the math element can help me with this, but I can't understand what does what, so I can't write anything out, sorry.
Upvotes: 0
Views: 120
Reputation: 2793
The string
methods can help out...
> function click(pin)
>> local rnd = math.random(#pin)
>> local dig = pin:sub(rnd, rnd)
>> return(pin:gsub('.', function(m) if m == dig then return(m) else return('*') end end))
>> end
> pin=1234567890
> click(tostring(pin))
*******8**
> click(tostring(pin))
*****6****
> click(tostring(pin))
********9*
> click(tostring(pin))
****5*****
pin
(dig = pin:sub(rnd, rnd)
)m == dig
) at its position the rest fill out with *
Upvotes: 2