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: Annoying String Problem with Commands

Previous Thread :: Next Thread 
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
09 Jul 2011 03:43 PM
This function 'getTeam' returns something correct when I use it with situation #1, but not with situation #2 even though they are supposed to be the same. I will post the output for each situation. For each case, assume the table 'teams' contains 2 tables, one holding "1 test" in its first index and the other, "2 test".

Here is the function:
function getTeam(name)
local t = 1
for _,v in pairs(teams) do
print("name:",name,"taking:",v[1])
print("sub:",v[1]:sub(1,name:len()))
if v[1]:sub(1,name:len()):lower() == name:lower() then
t = t == 1 and v or 2
end
end
if t ~= 1 and t ~= 2 then
print("team found")
return t
else
return nil
end
end

Situation #1: --this one runs exactly as expected
local m = msg:sub(9) --msg = "/getteam 1"
if m then
local t = getTeam(m)
if t then
local h = Instance.new("Message",speaker.PlayerGui)
h.Text = table.concat(t," ")
wait(4)
h:remove()
end
end

Output:
Team 2 test added
name: 1 taking: 1 test
sub: 1
name: 1 taking: 2 test
sub: 2
team found

Situation #2: --this one fails and I have no idea why
local n = 0
for i=6,500 do
if msg:sub(i,i) == "/" then --msg = "/duel 1/2"
n = i
break
end
end
local team1 = getTeam(msg:sub(7,n-1))
local team2 = getTeam(msg:sub(n+1))
print(team1,team2) --this is the part that outputs "nil nil"

Output:
name: 1 taking: 1 test
sub:
name: 1 taking: 2 test
sub:
name: 2 taking: 1 test
sub:
name: 2 taking: 2 test
sub:
nil nil --this part is not in the getTeam function output
Report Abuse
VictoriousMaxPower is not online. VictoriousMaxPower
Joined: 14 Jan 2010
Total Posts: 841
09 Jul 2011 03:49 PM
I think it's due to the fact that Team 1 has a number and an n (7,n-1) where as Team2 has just an n (n-1).
So maybe if you put 0.1 or something small...
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
09 Jul 2011 03:50 PM
You should read up on string.sub.
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
10 Jul 2011 01:41 AM
By the way, the 'Team 2 test added' in the first command is nothing to do with the script shown. It's from a part before it (which works).
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
10 Jul 2011 12:00 PM
local m = msg:sub(9) --msg = "/getteam 1"

Uh... that makes m equal to " 1", not "1"...

So as far as I can tell your code's set up in such a way that the wrong one works :P
Report Abuse
Anaminus is not online. Anaminus
Top 100 Poster
Joined: 29 Nov 2006
Total Posts: 5945
10 Jul 2011 12:00 PM
What is it supposed to do?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
10 Jul 2011 12:05 PM
And why on earth can't you just do something like this:

m = msg:sub(10) --msg = "/getteam 1"
n = tonumber(m)
t = teams[n]
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
10 Jul 2011 12:10 PM
Yep, when I run your code, the first one fails and the second one works.

So it looks like you made the same mistake somewhere else and teams actually contains " 1 test" and " 2 test", so the first one worked because it also had a space at the beginning, but the second didn't.
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
10 Jul 2011 12:11 PM
@Anaminus - #2 should output what #1 does.
@sncplay - because I want shortenings of names and the team may not always exist.

I think SNCplay was right with the first one, that's so annoying.
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