HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Setting integers through chat strings and displaying them

08-28-2008, 02:13 AM#1
Kwah
A Collection of GUI Systems > Basic to Advanced (Incomplete)

This tutorial teaches and explains how to construct a system, that when the player types a chat string, followed by a collection of numbers, a variable is set to the value of the entered numbers. I'll explain how to add a cap to the maximum as well. This tutorial is very simple but goes into a lot of detail. Remember to add a space after "-number "

Variables

  • YourInteger of type integer
  • And Later: YourInteger[] of type integer array

To start I'll begin with a few basic notes. First an explanation of "sub-strings". A substring is a string, or group of letters, that is part of another string. It is defined by what characters it is between. For example: The main string is "tutorial's are awesome" and the defined substring was Entered Chat String: 2,5. Begin at character 2 (u) and end at character 5 (r). Both 2 and 5 are included. in this case it would be: tutorial


Poorly Done Version

Trigger:
Trigger
Collapse Events
Player - Player 1 (Red) types a chat message containing -number as A substring
Conditions
Collapse Actions
Set YourInteger = (Integer((Substring((Entered chat string), 9, 12))))
Game - Display to (Player group((Triggering player))) the text: (YourInteger now = + (String(YourInteger)))

De-Construction

Is a simple way of doing it. Now, I'll de-construct it, explain and improve.

Trigger:
Player - Player 1 (Red) types a chat message containing -number as A substring

Is rather simple really. If the player (1 red in this case) types a chat message, containing the string "-number " then the event will trigger. This is not foolproof, so don't go rushing off yet.

Trigger:
Set YourInteger = (Integer((Substring((Entered chat string), 9, 12))))

Sets YourInteger (a integer variable) to the substring of the entered chat string. In this case it picks all of the characters, in between, 9 and 12 of your message, and converts them to an integer. If there are non-integer characters in this area (ie: a or b) it will ignore them.

Trigger:
(Game - Display to (Player group((Triggering player))) the text: (YourInteger now = + (String(YourInteger)))

Just, displays a message so that you know you got it right.


Getting Better!

There are however some issues with this message. What I will revise it to will look like this:

Trigger:
Trigger
Collapse Events
Player - Player 1 (Red) types a chat message containing -number as A substring
Player - Player 2 (Blue) types a chat message containing -number as A substring
Player - Player 3 (Teal) types a chat message containing -number as A substring
Player - Player 4 (Purple) types a chat message containing -number as A substring
Player - Player 5 (Yellow) types a chat message containing -number as A substring
Player - Player 6 (Orange) types a chat message containing -number as A substring
Player - Player 7 (Green) types a chat message containing -number as A substring
Player - Player 8 (Pink) types a chat message containing -number as A substring
Player - Player 9 (Gray) types a chat message containing -number as A substring
Player - Player 10 (Light Blue) types a chat message containing -number as A substring
Player - Player 11 (Dark Green) types a chat message containing -number as A substring
Player - Player 12 (Brown) types a chat message containing -number as A substring
Collapse Conditions
(Substring((Entered chat string), 1, 8)) Equal to -number
Collapse Actions
Set YourInteger[(Player number of (Triggering player))] = (Integer((Substring((Entered chat string), 9, 12))))
Game - Display to (Player group((Triggering player))) the text: ((|c00FFFF00 + (String(YourInteger[(Player number of (Triggering player))]))) + |r)

Before you try to do this the first thing you need to go is to go to your variables (ctrl-D). Click on the array box and set "Size = # of players in your map"

De-Construction

Now, I'll break it down again.

Trigger:
Events
Player - Player 1 (Red) types a chat message containing -number as A substring
Player - Player 2 (Blue) types a chat message containing -number as A substring
Player - Player 3 (Teal) types a chat message containing -number as A substring
Player - Player 4 (Purple) types a chat message containing -number as A substring
Player - Player 5 (Yellow) types a chat message containing -number as A substring
Player - Player 6 (Orange) types a chat message containing -number as A substring
Player - Player 7 (Green) types a chat message containing -number as A substring
Player - Player 8 (Pink) types a chat message containing -number as A substring
Player - Player 9 (Gray) types a chat message containing -number as A substring
Player - Player 10 (Light Blue) types a chat message containing -number as A substring
Player - Player 11 (Dark Green) types a chat message containing -number as A substring
Player - Player 12 (Brown) types a chat message containing -number as A substring

Just checks for all of the players exactly what it did for Player One in the first trigger. Remember to add a space after the "-number"

Trigger:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring((Entered chat string), 1, 8)) Equal to -number

This checks if the substring 1-8 ("-number ") actually says "-number ". This prevents players typing things like "10 -number ".

Trigger:
Then - Actions
Set YourInteger[(Player number of (Triggering player))] = (Integer((Substring((Entered chat string), 9, 12))))

And, now we get to the actions. This does the same thing as, before but with an array added. This means that they're are actually 12 different variables (One for each player). This means that each player can set their own YourInteger.

Trigger:
Game - Display to (Player group((Triggering player))) the text: ((|c00FFFF00 + (String(YourInteger[(Player number of (Triggering player))]))) + |r)

And, now we display the message. This time with pretty colour. use concatenate strings, and the colour codes on either side of the variable string.

Adding a Ceiling

Now, one last thing:

Adding a ceiling.

Trigger:
Collapse Trigger
Collapse Events
Player - Player 1 (Red) types a chat message containing -number as A substring
Player - Player 2 (Blue) types a chat message containing -number as A substring
Player - Player 3 (Teal) types a chat message containing -number as A substring
Player - Player 4 (Purple) types a chat message containing -number as A substring
Player - Player 5 (Yellow) types a chat message containing -number as A substring
Player - Player 6 (Orange) types a chat message containing -number as A substring
Player - Player 7 (Green) types a chat message containing -number as A substring
Player - Player 8 (Pink) types a chat message containing -number as A substring
Player - Player 9 (Gray) types a chat message containing -number as A substring
Player - Player 10 (Light Blue) types a chat message containing -number as A substring
Player - Player 11 (Dark Green) types a chat message containing -number as A substring
Player - Player 12 (Brown) types a chat message containing -number as A substring
Collapse Conditions
(Substring((Entered chat string), 1, 8)) Equal to -number
Collapse Actions
Set YourInteger[(Player number of (Triggering player))] = (Integer((Substring((Entered chat string), 8, 99))))
Collapse
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
YourInteger[(Player number of (Triggering player))] Greater than or equal to 500
Collapse Then - Actions
Set YourInteger[(Player number of (Triggering player))] = 500
Game - Display to (Player group((Triggering player))) the text: ((|c00FFFF00 + (String(YourInteger[(Player number of (Triggering player))]))) + |r)
Collapse Else - Actions
Set YourInteger[(Player number of (Triggering player))] = (Integer((Substring((Entered chat string), 9, 12))))
Game - Display to (Player group((Triggering player))) the text: ((|c00FFFF00 + (String(YourInteger[(Player number of (Triggering player))]))) + |r)

De-Construction

Lets take a more detailed look.

Trigger:
Collapse If - Conditions
YourInteger[(Player number of (Triggering player))] Greater than to 5000
Collapse Then - Actions
Set YourInteger[(Player number of (Triggering player))] = 5000

Simply, if <YouInteger>[Trigger Player Number] is larger than 5000, it resets it to 5000.

With the addition of a simple if/then/else the ceiling (maximum value) is added. If you want it so that it has no effect, then just leave the area blank. Instead of re-setting the variable.


Additional Note

You could replace the integer with a real if you wanted, just change the variable type and all of the conversions.

This wraps up my tutorial here. I hope that you enjoyed it, and that you find it useful. If you think that I need to improve something, or have found a bug, then please contact me.

Thanks to PurplePoot for pointing out a further refinement.

Conclusion

Using this system will not cause any bugs that I have discovered yet. For example, if you include letters or other characters in with your integers they will be ignored, and only the numbers input. This creates a system that the players have little oppurtunity to abuse, or destroy. If the players input fewer than the number of characters in the sub-string, it will still work so no worries there. If you want unlimited amounts, just forget the ceiling and use the previous version.

Changelog



~Updated Demo Map. Now has add gold, and spawn.
~Changed if/then/else to condition
~Fixed Error with order of ceiling in demo
~ Updated at request of PitzerMike

Attached Files
File type: w3xSettingIntegersThroughChat.w3x (16.8 KB)
08-28-2008, 05:25 AM#2
The Elite
no way for you to change the thread name, but ask a mod
08-28-2008, 05:33 AM#3
Kwah
Thanks, I've changed the message.

Anything to say about the tutorial?
08-28-2008, 09:07 AM#4
Tide-Arc Ephemera
It's a bit narrow content wise and I can't exactly explain what I'm seeing...

However, it is a good tutorial. My suggestion - make a small demo map with this implemented and make it have gold donating or creep spawning that relies on input integers.

There's also ways to do this without use of variables, but yeah this is pretty handy.

+ Rep, I had huge ass-pains trying to learn this but I'm sure it'd be useful to others.
08-28-2008, 04:35 PM#5
Kwah
Thanks, I'm going to add other systems soon. Thanks, I thought that it would round out rather well.

Quote:
It's a bit narrow content wise and I can't exactly explain what I'm seeing...

However, it is a good tutorial. My suggestion - make a small demo map with this implemented and make it have gold donating or creep spawning that relies on input integers.

There's also ways to do this without use of variables, but yeah this is pretty handy.

+ Rep, I had huge ass-pains trying to learn this but I'm sure it'd be useful to others.

Variables are more dynamic than not, so I use them instead. They also make the code easier to read.

I'll get to work on a better demo map soon.

EDIT: Demo map updated. Added add gold, and spawn as well as original.
08-28-2008, 07:30 PM#6
Anopob
Seems pretty good, you probably want to make the syntax for the commands both in WE and in Warcraft much clearer and obvious, though.
08-28-2008, 07:36 PM#7
Kwah
Quote:
Seems pretty good, you probably want to make the syntax for the commands both in WE and in Warcraft much clearer and obvious, though.

What do you mean? -number, -spawn, -gold? How is that compilcated?
08-29-2008, 04:57 AM#8
Anopob
I mean make a message displaying the entire syntax, I couldn't figure out the -spawn one (even after looking in WE), but I guess that's just me, so nevermind. Good work on the triggers though.
08-29-2008, 05:06 AM#9
Kwah
Quote:
I mean make a message displaying the entire syntax, I couldn't figure out the -spawn one (even after looking in WE), but I guess that's just me, so nevermind. Good work on the triggers though.

-spawn 1 or 2 or 46 is correct. Not the word. That should help.
09-04-2008, 07:56 PM#10
Kwah
Well, I might be a little while on the next few, because I'm joining a THW contest, and it should take a while. Still, they WILL come.
09-04-2008, 08:29 PM#11
Kyrbi0
~Off-Topic~

Hey, are you the same "hawk900" that's joining the Race Olympics over at the Hive?
09-05-2008, 12:01 AM#12
Kwah
That is me. :p

Any comment on the tutorial itself?
09-05-2008, 11:34 AM#13
Kyrbi0
Well, I guess I'm looking forward to "Effect On Attack"; is that basically using Dummy Casters, or something else entirely?

~Off-Topic~
Good luck on THW contest... May be the best team win. :P
09-05-2008, 07:12 PM#14
Kwah
Quote:
Well, I guess I'm looking forward to "Effect On Attack"; is that basically using Dummy Casters, or something else entirely?

~Off-Topic~
Good luck on THW contest... May be the best team win. :P

Dummy casters, and I MIGHT get some attack detection, orb effects going, if feel that motivated.
09-13-2008, 07:25 PM#15
Kwah
I am going to keep working on these, but I may release them seperatly as different systems, depending on how complicated they are.

I'll include the basic ones here, and make the harder to understand ones, each with a seperate update.