Understanding Integer A & Substring Functions

Mr.Tutorial

Hard in the Paint.
Reaction score
42
Alright, so I kind of understand integer A but I don't understand substring at all. I want a better knowledge of these to help make smaller triggers.

1: Explain Substring and how the "2,4" stuff works... (Detail Please)

What I understand of this: None

2: Please also explain integer A and different options in which it can be used.
What I understand of this: I know you can loop integer a from 1-10 and allow it to be used by using (Integer A) function, but what else can you use it for?

If you can't explain, and you know of any tutorials or such please post, thanks! Good explanation gets reputation!
 

Flare

Stops copies me!
Reaction score
662
1) Substring (x, y) takes the (x)th and (y)th term in your given string (spaces included) and forms a new string from that.

Example:
Main string = Warcraft
Substring (1, 3) = War
Substring (2, 5) = arcr
Substring (4, 8) = craft

What I understand of this: I know you can loop integer a from 1-10 and allow it to be used by using (Integer A) function, but what else can you use it for?

You can use it for looping through players (let's say if you want to check which players have more than 1000 gold, just do an integer loop and check Player (integer A)'s current gold.

Can also be used for looping through arrays (if you want to cycle through X units in an array [assuming their array values are consecutive numbers, its hard to skip numerous values with an integer loop], but those X units aren't in a single group)
 

Mr.Tutorial

Hard in the Paint.
Reaction score
42
1) Substring (x, y) takes the (x)th and (y)th term in your given string (spaces included) and forms a new string from that.

Example:
Main string = Warcraft
Substring (1, 3) = War
Substring (2, 5) = arcr
Substring (4, 8) = craft



You can use it for looping through players (let's say if you want to check which players have more than 1000 gold, just do an integer loop and check Player (integer A)'s current gold.

Can also be used for looping through arrays (if you want to cycle through X units in an array [assuming their array values are consecutive numbers, its hard to skip numerous values with an integer loop], but those X units aren't in a single group)

I still don't understand how substring works. So if the main substring is Warcraft why would "War" be (1, 3)?
 

MerrillPhish

Active Member
Reaction score
10
For Loops are the best thing ever once you learn to use them here is a trigger I use for Spawning in TD's. It uses For loop with Int A.

First off I Set An Array Regions like this...

Set Spawn_Region[1] = 1 <gen>
Set Spawn_Region[2] = 2 <gen>
And so forth


Then when i want to spawn...
instead of typing alot of code i Just use one simple For Loop


For each (Integer B) from 1 to 20, do (Actions)
Loop - Actions
-------- Spawn Units --------
For each (Integer A) from 1 to 8, do (Actions)
Loop - Actions
Set Temp_Point = (Center of Spawn_Region[(Integer A)])
Unit - Create 1 Level_Unit_Type[(Level)] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
Custom script: call RemoveLocation(udg_Temp_Point)


That Make Sense?
 

takethat

Active Member
Reaction score
12
it is because war is the 1st aph to the 3rd aph in the word "warcraft"

the number (x,y) is for u decide from which aph to which aph u want to taken out from the main string


technically i used this to detect how many kills you want to have in my map
eg: you type -km200

i use the substring to take out 200 by using (4,6)

Code:
off topic:
then i convert the string to integer to set max kills
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
If you put substring(1, 3) you take letter number 1, 2 and 3 from the string.

Substring(1, n) takes letter number 1, 2, 3, 4, ...n.

Example:

Warcraft

Substring (1, 3)

1st letter: W
2nd letter: a
3d letter: r

Substring(1, 3) = W+a+r = War.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Let me take another approach.

12345678
warcraft

Each letter corresponds with the number above it.

(1, 3)

Same as saying "From 1 to 3"
Well, which letter is 1?

12345678
warcraft

Looks like "w"

So, which one is 3 (the end)?

Looks like "r"

Include any in between and give that back to you.

"war"

There you go. Pretty easy, no?
 

MoonSlinger

I Love using Cheap Tricks... only Results matters
Reaction score
74
[SIZE="+1"]For Loop Integer[/SIZE],
basically the limit to the usage can only be stopped by your imagination.

-> Mostly it is used with Arrays to make repetitive task simple, as the example provided above regarding spawning creeps.
-> You can used it with regards to player functions to since all players come with a player number (as mentioned above)
-> It is also used in multiboards to set all necessary cells to certain color, and/or to display icons

Or you can do something more interesting like: :nuts:
Code:
Running Explosion
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Run Explosion
    Actions
        For each (Integer B) from 1 to 1000, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Active[(Integer B)] Equal to False
                    Then - Actions
                        -------- Initialization --------
                        Set Active[(Integer B)] = True

                        -------- These attributes are unique to each casting --------
                        (Triggering unit)
                        (Target point of ability being cast)
                        (Target unit of ability being cast)

                        -------- Run Spell Effect --------
[COLOR="Red"]                        For each (Integer A) from 1 to 10, do (Actions)
                           Loop - Actions 
                              Create a Goblin Land Mine at (Position of (Triggering unit))
                              Explode (Last Created Unit)
                              Wait 0.5 second[/COLOR]

                        -------- Free-Up the Space you are using --------
                        Set Active[(Integer B)] = False
                        Skip remaining actions
                    Else - Actions
                        Do nothing
        Game - Display to (All players matching ((Owner of (Triggering unit)) Equal to (Matching player))) the text: Spell Fizzle As there are already 1000 instance happening

I think I am the only person using Loops in this way, but as mentioned, their uses are only limited by your imagination. :thup:

With the above code, you can have up to 1000 units doing the same spell at the same time. Personally, I think you computer would lag itself to death before you need to get more instances.... :D

Anyway, I didn't remove leaks, so if you intend to use it, remove the leaks first. :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top