Converting string to real, after "Word Of String"

WarToast

Active Member
Reaction score
3
Solved
Solved
Solved

Hey,

So I'm trying to make this function that lets a player type in a message, and the camera will then zoom in or out depending on what the player wrote.

The way I wanted this is that you can type "-cam 200", and the camera will zoom to a distance of 200. You can also type "-cam 201", and it will zoom to 201, and so on. That means I won't work with fixed values.

So this is the way I made it so far. I have the player type in a message that contains "-cam", and then I want my trigger to pick the second word in the string (which would be 200 in the above example), convert it to a real and then use it in my action.

capturesg.png


Now the problem is that, in the local variables section, I want to use my String zoomLevelInput in the real convertedOutput. Since I convert from string to real, I figured I could use my String variable, but no. (Right now there is just the (Entered chat string) because I couldn't pick my own variable)

So basically, my question is: How would I pick the second word in the chat string, convert it to real so I can use it in my camera options?

Bonus question: Does the "partial match" of my event also trigger if a user types "Hello -cam"? In that case, the "Word of String" wouldn't work, and I would be looking for a new solution.

Thanks
Edit: I just answered by own bonus question; it does trigger even if -cam isn't the first word.
 

Flare

Stops copies me!
Reaction score
662
Edit: I just answered by own bonus question; it does trigger even if -cam isn't the first word. I will just set it to exact match
If it's anything like Warcraft 3, wouldn't Exact Match require you to type -cam alone, resulting in you being able to add your distance 'parameter' to the chat text - in which case, you would probably be looking for -cam as a partial match with Substring (1,4) or (0,3) depending on how GUI substrings work) == -cam

Also, Text and String are different variable types - enteredChatText should be changed to a string type :)
Trigger:
  • Cam trig
    • Events
      • Game - Player Any Player types a chat message containing "-cam", matching Partially
    • Local Variables
      • EnteredString = "" <String>
      • Substring = "" <String>
    • Conditions
      • (Substring((Entered chat string), 1, 4)) == "-cam"
    • Actions
      • Variable - Set EnteredString = (Entered chat string)
      • Variable - Set Substring = (Substring(EnteredString, 6, (Length of EnteredString)))
      • Camera - Set (Default game camera) Distance to (Real(Substring))

Perhaps that would work (replacing 'Default game camera' with whatever camera value you're using there)

EDIT: Oh, you're using Word of String... in that case, you might want to try some testing with " -cam" incase the addition of a space before -cam results in it being counted as the second word. I'm guessing
Trigger:
  • Variable - Set Substring = (Word 2 of (Entered chat string))

would work in place of the 2 variables I used above.

Either way, you will need a condition; any chat command that has 2 (or more) components will always need conditions to ensure that the syntax is correct (i.e. is -cam the first part of the chat message, you may also have to add a condition to check if the entered value is within a certain range, such as positive values only) - Partial Match isn't at fault in any way in this situation :p

EDIT AGAIN: Also, does setting a value for local variables, within the local variable block work? I've always been doing it within the actions xD

FINAL EDIT: OK, this works
Trigger:
  • Cam trig
    • Events
      • Game - Player Any Player types a chat message containing "-cam", matching Partially
    • Local Variables
      • EnteredString = "" <String>
      • CamValue = 0.0 <Real>
    • Conditions
      • (Substring((Entered chat string), 1, 4)) == "-cam"
    • Actions
      • Variable - Set EnteredString = (Entered chat string)
      • Variable - Set CamValue = (Real((Word 2 of EnteredString)))
      • Camera - Apply camera object Distance CamValue for player 1 over 2.0 seconds with Existing Velocity% initial velocity and 10% deceleration

Just change 'player 1' to Triggering Player :)

Default camera distance is 34.07, so I'd recommend adding a condition to cap the distance at something below 100 (perhaps a cap lower than that)
 

WarToast

Active Member
Reaction score
3
Ah I realised my error before. I couldn't convert my string variable to real because I clicked wrong... It should work now.

And thanks, I am basing my version on the last of your submissions. Now I need to make it only act if it's a number within my (to be defined) bounds and of course that it is actually a number.

If it's just letters it will fuck up somehow. I'll update


EDIT: I continued today, and now it works as supposed. If the word that comes after "-cam" is not a number, the function will return 0. So when a player types -cam, I simply check if the camValue variable is > 0, and in my case camValue < 43.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top