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.
 
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)
 
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.
  • Varine Varine:
    +1
  • Varine Varine:
    I've been really into this
  • Varine Varine:
    It's a musical retelling of The Odyssey
  • Varine Varine:
    Also if you want mixed drinks without alcohol, there's a handful of non-alcoholic 'spirits'. Ritual Zero and Free Spirit are the two brands I've tried and they are alright. They don't have a TON of options, but they have some gin and whiskey alternatives that are fun to play with.
  • Varine Varine:
    I got a couple bottles to make some mixy drinks around holidays when I mostly want to drink, they aren't exact replacements but they are surprisingly close.
  • Varine Varine:
    I ended up with some hop water things that I really like instead for when I want to feel like I'm participating
  • Varine Varine:
    I just got moved to unsupervised probation, so I can get away with drinking a bit now. I technically am not supposed to, but I don't think I get checked anymore. I really want to smoke weed but it scares me
  • The Helper The Helper:
    Happy Wednesday! I am not feeling it today, my teeth are bothering me, or the fragments that were left behind are coming up and it is extra painful today. Don't ever let them tell you that getting full dental implants is easy. They have to pull all your teeth to do those and apparently they are not very good at getting all the teeth out all the time.
    +1
  • The Helper The Helper:
    That is true with Dentures too. I am taking the day off and working from home. The big difference is though, I am not drinking anymore so I have a nice tea and coffee regimen set up :)
  • Varine Varine:
    I wish i had a 3D scanner
  • Varine Varine:
    That would make what I'm doing SO much easier
  • Varine Varine:
    I guess I could just take a picture of it and then use that as a reference. I have a circuit board with some weird holes I can't get measured right
  • Varine Varine:
    Oh I got a Klipper mod for my big printer! It comes with a bunch of parts and I don't totally understand what it does but apparently it's way better than Marlin, which is I think what it currently runs
    +1
  • The Helper The Helper:
    Nice!
  • Varine Varine:
    You're people in Florida safe? The only couple I know are safe but I think they evacuated.
  • The Helper The Helper:
    They are without power but safe. Flood damage and stuff alot of tornados hit east Florida. No fatalities or injuries to any of my people that I know of
  • The Helper The Helper:
    They have been through all the Florida hurricanes they are like me I have been through every texas hurricane for the last 50 years.
  • The Helper The Helper:
    Never evacuated.
  • The Helper The Helper:
    Check out this bad ass Chicken Noodle soup recipe - https://www.thehelper.net/threads/crack-chicken-noodle-soup.196687/
  • The Helper The Helper:
    Happy Saturday!
    +1

      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