Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xIvan95 · Mar 09, 2014 at 10:56 PM · inputstringvalue

Help with a string format input

Hi! I am making a game which uses kind of a string format (I don't know how to call this) to get the player's keyboard input and execute an action based on that string format.

I'll explain it with an example:

  • We are in a MMORPG world (think WoW) and we can use the keyboard to chat and to execute commands. These commands are made up of multiple strings put together to make something to happen.

For example "hit the enemy with 2 points of power". This command is set up with 3 variables (something like hitattack (string), enemytarget (string) and powerpoints (int) but the command makes use of the variables turned into strings, but if you modify the string, the variable value will change too, so if you type those 3 elements, something will happen.

I'll try with another example as I know this is hard to explain (sorry guys):

  • You need to combine multiple variables turned into strings (so if you have a float 0.6f it will turn into a string "0.6" and so on...) to execute a command line, which depending on the values you set to a float, it will turn the float value into a string, but it will make use of the float value.

Sorry if I make this harder, if you guys still don't understand me, I'll try with more examples. Thank you sooooo much! You are awesome!

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Mar 09, 2014 at 11:17 PM 0
Share

As a design question, you may be better served posting this on Unity forums...or another program$$anonymous$$g forum since there is nothing Unity in this question. Parsing text like this can be fairly simple or very complex depending on the allowed language and syntax. For example, what if the user typed "Apply 2 point of power to hitting the enemy?" Okay? Not okay? What about 'two' ins$$anonymous$$d of '2'? What about misspellings? What are the restrictions to your language? Being specific about scope and rules will really help you get a good answer.

avatar image ozone · Mar 09, 2014 at 11:27 PM 0
Share

What scripting language to you prefer? This should be relatively easy to do using GUI.TextField and the C# String.Split method as long as each of the variables that the string must assign the value of are separated by a specific character (e.g. each is one word, and they are separated by spaces, so the command in your example would be more like "hit enemy 2" ins$$anonymous$$d of "hit the enemy with 2 points of power").

avatar image xIvan95 · Mar 09, 2014 at 11:43 PM 0
Share

Yeah, I know it. But I only need the basic idea to develop this, as I have been testing but I can't find it :/ Thanks anyway, I'll keep trying till someone helps me ^^

Edit: I use C# and I think it could be either easy or difficult depending on the way I make it, but I only need some basic info

avatar image robertbu · Mar 10, 2014 at 12:36 AM 0
Share

If you confine your language to three things, an action, an object, and an amount, this can be fairly easy. First create an array of strings for each action. It would contain things like 'hit', 'lift', 'bribe', 'break' 'cast', 'chop', etc. Then a list of objects like 'enemy', 'door', 'wizard', 'troll', etc. When the user submits a command, look in the string to see if any action words exist. You can cycle through the array of actions and use 'string.Contains()' on the submitted string to check. If you find one, you have your action. If none exist, then the string is invalid. Do the same thing with the list of objects. Then find the first occurrence of a digit and parse out a value. This is a very flexible solution since the user can input the string in a variety of ways, but it also will parse out valid commands from nonsense or ambiguous strings.

avatar image SirCrazyNugget · Mar 10, 2014 at 02:26 AM 0
Share

Do you mean an AI editor? I've never played WoW but have seen one in a couple of other games, just googled it and came up with this.

If that's the kind of thing that you're after then as robertu proposed just implement an array of known strings and have the user either type or choose them from multiple drop-down lists.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detecting if an input was something other then a specified character (C#) 2 Answers

Redirecting input with event.current.character? 1 Answer

Checking whether string is a valid Input.Key 1 Answer

Android Keyboard .text String returning empty? 1 Answer

imeCompositionmode 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges