• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Creating Integer from Chat String

Status
Not open for further replies.
Level 4
Joined
Apr 14, 2014
Messages
98
I'd like to do this procedure. I can't get the syntax right in GUI:

Please don't type this in JASS unless you can give me a link to a tutorial.

when player Red types a chat message containing <four char int> as an exact match
<four char int> is converted to <int var> Time
set time of day to Time
 
Last edited:
Level 12
Joined
Mar 24, 2011
Messages
1,082
First of all game Time of Day is measured in reals not integers
To avoid a player just wanting to type in a number but instead setting up the time of the day you may want something like this:

  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -set time as A substring
    • Conditions
    • Actions
      • Set EnteredChatString = (Substring((Entered chat string), 11, 15))
      • Set TimeOfDay = ((Real(EnteredChatString)) / 100.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TimeOfDay Greater than or equal to 0.00
          • TimeOfDay Less than or equal to 24.00
        • Then - Actions
          • Game - Set the time of day to TimeOfDay
        • Else - Actions
          • Game - Display to (All players) the text: Clocks do not work ...
EnteredChatString - variable of type String
TimeOfDay - variable of type Real
 
Level 4
Joined
Apr 14, 2014
Messages
98
Thanks.

When I go into game and -set time as 1000; instead of setting the time to what I expect to be 10:00AM, the clock is set to midnight (0).

A few things I don't understand what the functions are doing. When I call a substring, what do the parameters 11, 15 modify or represent?

When I convert my String to Real, how am I converting it? Is my String going through correctly?

  • Time
    • Events
      • Player - Player 1 (Red) types a chat message containing -set time as as A substring
    • Conditions
    • Actions
      • Set EnteredChatString = (Substring((Entered chat string), 11, 15))
      • Set TimeOfDay = (Real(EnteredChatString))
      • Set TimeOfDay = (TimeOfDay / 100.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TimeOfDay Greater than or equal to 0.00
          • TimeOfDay Less than or equal to 24.00
        • Then - Actions
          • Game - Set the time of day to TimeOfDay
        • Else - Actions
          • Quest - Display to (All players) the Quest Update message: Failed to set time.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
When I go into game and -set time as 1000; instead of setting the time to what I expect to be 10:00AM, the clock is set to midnight (0).
This is because for some reason TimeOfDay is less than 0 or bigger than 24.
Look here:
  • Player - Player 1 (Red) types a chat message containing -set time as as A substring
Now look at my code
  • Player - Player 1 (Red) types a chat message containing -set time as A substring
Now look at the string explanation to understand.

A few things I don't understand what the functions are doing. When I call a substring, what do the parameters 11, 15 modify or represent?
Ok, an array of characters is called a string, meaning that each symbol has a numeric representation.

1 = -
2 = s
3 = e
4 = t
5 =
6 = t
7 = i
8 = m
9 = e
10 =
11 = 1
12 = 0
13 = 0
14 = 0

So you are taking 11 to 15 from "-set time 1000" and making a new string which is "1000". From the above you see that I have made a little mistake and it should be 11 to 14. And again from the above you can see that spaces DO COUNT.

1 = -
2 = s
3 = e
4 = t
5 =
6 = t
7 = i
8 = m
9 = e
10 =
11 = a
12 = s
13 =
14 = 1
15 = 0
16 = 0
17 = 0

Therefore 11,14 is "as 1", therefore your real is a LOT bigger than 24, characters have a numeric value which is between 0 and 255 (war3 uses ascii right ?) so they can too be represented as numbers.

  • Time
    • Events
      • Player - Player 1 (Red) types a chat message containing -set time as as A substring
    • Conditions
    • Actions
      • Set EnteredChatString = (Substring((Entered chat string), 11, 15))
      • Set TimeOfDay = (Real(EnteredChatString))
      • Set TimeOfDay = (TimeOfDay / 100.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TimeOfDay Greater than or equal to 0.00
          • TimeOfDay Less than or equal to 24.00
        • Then - Actions
          • Game - Set the time of day to TimeOfDay
        • Else - Actions
          • Quest - Display to (All players) the Quest Update message: Failed to set time.

When I convert my String to Real, how am I converting it? Is my String going through correctly?
Yes, because time of day is between 0 and 24. Because the player is required to type in 4 digit number you get a value way above these, dividing by 100 makes it just right. Still it is not entirely safe if someone decides to start fucking with it but the conditions at least limit this.
 
Status
Not open for further replies.
Top