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 » Scripters
Home Search
 

Re: So much trouble with strings right now

Previous Thread :: Next Thread 
classy_chap is not online. classy_chap
Joined: 14 Mar 2009
Total Posts: 338
26 Jun 2016 12:52 AM
I don't know why i'm having so much trouble but at this point i'm frustrated.

I've been trying to take the player's message and do something like this:

player says: ":health Player1 10"

it chops it up and finds which one is the Prefix, ":health" and which one is the suffix "10"

but every time I try to do this... something happens and I just get frustrated beyond belief. Could anyone help me out?


Report Abuse
seanbenish is not online. seanbenish
Joined: 31 Jul 2009
Total Posts: 429
26 Jun 2016 12:56 AM
Why not just chop it up at the whitespace, and then input it into a table for usage and arguments?


public static void main(String[] args) { System.out.println("Oops! Wrong language."); }
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
26 Jun 2016 12:56 AM

local cmd = {}
for str in msg:gmatch("%w+") do table.insert(cmd, str:lower()) end

local prefix = cmd[1]
local player = cmd[2]
local suffix = cmd[3]


#code R+ | local RAP = "R$725,838"; local robux = "R$11,041";
Report Abuse
classy_chap is not online. classy_chap
Joined: 14 Mar 2009
Total Posts: 338
26 Jun 2016 12:58 AM
I don't need a table.. I need a way to chop it up.


Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
26 Jun 2016 01:00 AM
you need a table.


#code R+ | local RAP = "R$726,080"; local robux = "R$11,041";
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
26 Jun 2016 01:02 AM
@Abs
You don't need a table, but its quite confusing on how it works. Aka string.sub().


-=[ RAP: 326,973 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
seanbenish is not online. seanbenish
Joined: 31 Jul 2009
Total Posts: 429
26 Jun 2016 01:06 AM
The table is there to store the strings so that their functions can be directly declared.

For example, if the input is ":health Player1 10", it would create a table with {":health","Player1","10"}.

With this, you could call the function like this

if table_of_commands[table_of_input[1]:sub(2)] then
local run = table_of_commands[table_of_input[1]:sub(2)]
table.remove(table_of_input,1)
run(table_of_input)
end

This will test if a command of that name exists, and then it will execute it. This uses Lua's table function, so all of the commands' function must be under the table "table_of_commands", or whatever you want its name to be.


public static void main(String[] args) { System.out.println("Oops! Wrong language."); }
Report Abuse
classy_chap is not online. classy_chap
Joined: 14 Mar 2009
Total Posts: 338
26 Jun 2016 01:09 AM
nah man, i'm trying to do it without any tables


Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
26 Jun 2016 01:10 AM
@Sean
You've lost me. I'm confused now.


-=[ RAP: 327,010 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
seanbenish is not online. seanbenish
Joined: 31 Jul 2009
Total Posts: 429
26 Jun 2016 01:13 AM
@Dur

Sorry m8. I guess I did make it seem a bit messy -v-

But the basis of that code is that there is a table of functions, whose name is the command name(save the ":"). This code just detects that, from a table given by the string, if a function in that "function table" exists, and if so, it executes it, but its input is the rest of the input table, in which the command itself (the first word) is removed.


public static void main(String[] args) { System.out.println("Oops! Wrong language."); }
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
26 Jun 2016 01:25 AM
@Sean
I'm not quite sure how its executing the command. Maybe its something I'm not seeing in your code.


-=[ RAP: 326,982 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
seanbenish is not online. seanbenish
Joined: 31 Jul 2009
Total Posts: 429
26 Jun 2016 01:30 AM
if table_of_commands[table_of_input[1]:sub(2)] then --runs code if function exists
local run = table_of_commands[table_of_input[1]:sub(2)] --creates function "pointer"
table.remove(table_of_input,1)--removes the function name from the table
run(table_of_input)--runs the function
end


public static void main(String[] args) { System.out.println("Oops! Wrong language."); }
Report Abuse
xThe_Developer is not online. xThe_Developer
Joined: 07 Aug 2013
Total Posts: 585
26 Jun 2016 01:39 AM
Took me a bit of tampering you may need to do the same as well but..
I'd start off by using gsub to clean up the string and get rid of possibly /e and the prefix..

Then I'd use str:match("(%a+)%s") to get the first word and run that against my commands table and if it's a command.. Then you'd want to continue moving on from there in many different ways.. One being to get rid of the command and space you just found and running the same proccess again on the next one and probably make it check if it's a number instead and go from there.


#code mod = require(sike) if not mod.xThe[...] then print("You're not RbxDev yet..") end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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