generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Mix up a word with string maniupulation?

Previous Thread :: Next Thread 
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 07:35 PM
How would I scramble a word with string manipulation?

For example my word is:

word

Then i scramble and get something

rwdo
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 07:36 PM
Then I scramble it and get something like:*
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 07:51 PM
Bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 07:55 PM
Show us what you go so far
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 07:56 PM
Oh pssht, you want one.

I guess you can just use a loop
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 07:56 PM
Nothing, I'm not very good with string manipulation.

Could gsub be used?
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 07:59 PM
Cnt, what would I put in the loop?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 08:01 PM
This is probably a bad way but:

local str = "hello"
local random = ""

local history = {}
for i = 1, #str do
repeat rnd = math.random(1, #str) until not history[rnd]
random = random .. str:sub(rnd, rnd)
end
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 08:30 PM
How would I make one that mixes up every word in a string?
for example, string normal would be "I am a string" and string mixed up would be "i ma a trsign'
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 08:40 PM
local str = "hello there"
local random = ""

local z = {}
for x in str:gmatch("%S+") do
table.insert(z, x)
end

local history = {}

for i = 1, #z do
for x = 1, #z[i] do
repeat rnd = math.random(1, #z[i]) until not history[rnd]
random = random .. z[i]:sub(rnd, rnd)
end
random = random .. " "
end

probably won't work but w/e

Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
12 Nov 2013 08:46 PM
function scramble(string)
local pivot = math.random(#string / 2, #string)
estring = ""
for i = 1, #string do
estring = string:sub(pivot, pivot)..estring
pivot = pivot+1
if pivot > #string then
pivot = 1
end
end
print(estring)
end
scramble("word")
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 08:53 PM
Cnt, your function kept the same length on either word but the word was compromised of random letters from the entire string.

Anybody else have an idea?
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
12 Nov 2013 08:59 PM
function scramble(string)
estring = ""
for z in string:gmatch("%w+") do
for y in string:gmatch("%s") do
local pivot = math.random(#z / 2, #z)
for i = 1, #z do
estring = estring..z:sub(pivot, pivot)
pivot = pivot+1
if pivot > #z then
pivot = 1
end
end
estring = estring..y
end
end
print(estring)
end
scramble("word hi")

Output:

rdwo ih
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 09:00 PM
Thanks, flatline!
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 09:04 PM
local input = "Hello There"
local output = ""

local splittedInput = {}
local lastHistory = {}

for value in input:gmatch("%S+") do
table.insert(splittedInput, value)
end

for word = 1, #splittedInput do
for index = 1, #splittedInput[word] do
repeat randomNumber = math.random(#splittedInput[word]) until not lastHistory[randomNumber]
lastHistory[randomNumber] = true
output = output .. splittedInput[word]:sub(randomNumber, randomNumber)
end
output = output .. " "
lastHistory = {}
end

print(output)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 09:05 PM
pssht I was late, stupid d/c'd internet
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
12 Nov 2013 09:07 PM
This works better actually as there was a weird error with my 2nd.

function check(table, string)
for i,v in pairs(table) do
if v ~= string then
return true
end
end
return false
end

function scramble(string)
estring, check2 = "", {}
for z in string:gmatch("%w+") do
check(check2, z)
table.insert(check2, z)
local pivot = math.random(#z / 2, #z)
for i = 1, #z do
estring = estring..z:sub(pivot, pivot)
pivot = pivot+1
if pivot > #z then
pivot = 1
end
end
estring = estring.." "
end
print(estring)
end
scramble("word hi k pop")
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 09:15 PM
Mine is shorted and more swaggy
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 10:16 PM
One more question, would there be a way to change the amount of characters scrambled per string?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 10:17 PM
yes, but whyyyy
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 10:43 PM
TBH, I have alchohol im my game and a custom chat GUI. The more tipsy you get, the more jumbled your speech.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 10:44 PM
guarrarararara l0l
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 11:02 PM
So can you help?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Nov 2013 11:03 PM
You are probably going to be banned but it really depends how you are going to use it
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
12 Nov 2013 11:42 PM
The drinks are all named "SomeColorHere Drink"

The bartender tells you, after buying a drink, 'Don't drink to much, you'll get dizzy!'


I've childproofed the heck out of it. Can you help me out with the last request or not>
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image