HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

textmacro loops

04-13-2009, 04:13 AM#1
Vexorian
so after coding modules, I feel like recoding textmacros so they have things like nesting and loops.

A textmacro loop is supposed to fix that problem people have some times, have you ever created 100 rects in a map to then figure out you need to add all of them to a region?

Collapse JASS:
     call RegionAddRect(r, gg_rct_ar001)
     call RegionAddRect(r, gg_rct_ar002)
     call RegionAddRect(r, gg_rct_ar003)
     call RegionAddRect(r, gg_rct_ar004)
     call RegionAddRect(r, gg_rct_ar005)
...

So a textmacro loop should be able to do that. You give it numbers 1 and 4 and then it repeats the same text macro over and over again.

The question is: give me syntax for that. Remember these are textmacros so it is supposed to be //! - based.

Collapse JASS:
//! textmacro addreg takes i
     call RegionAddRect(r, gg_rct_ar00$i$ )
//! endtextmacro

// (insert syntax to run addreg from 1 to 9 here)

04-13-2009, 04:24 AM#2
FriendlyPsycho
Collapse JASS:
//! runtextmacro for n to N addreg(LOOP_COUNT)
//! runtextmacro addreg(LOOPCOUNT) for n to N

LOOP_COUNT is the, well the integer 'n'. "for n to N" is a for-loop syntax.
04-13-2009, 05:08 AM#3
TriggerHappy
Collapse JASS:
//! runtextmaco addreg(LOOP_COUNT)  while i < 10
//! runtextmaco addreg(LOOP_COUNT)  until i == 9

Of course, allow the standard comparison operators.
04-13-2009, 06:40 AM#4
MaD[Lion]
OMG add this and.. and ill abuse it more. ive stopped abusing textmacros cus u didnt add such uberness HAPPY! :D
04-13-2009, 07:19 AM#5
Strilanc
Just have it be MIN:MAX instead of a string literal.

Collapse JASS:
//! runtextmacro name("some_arg", 0:99, "some_other_arg")
04-13-2009, 08:28 AM#6
Ammorth
Quote:
Originally Posted by Strilanc
Just have it be MIN:MAX instead of a string literal.

Collapse JASS:
//! runtextmacro name("some_arg", 0:99, "some_other_arg")


I like this. Would also be nifty if it would recognized 99:0 and start high and subtract to the low.
04-13-2009, 09:26 AM#7
akolyt0r
this solution misses an identifier for the index.
04-13-2009, 12:12 PM#8
peq
maybe this is too complicated, but i would like to see something like this if you expand textmacros.

Collapse JASS:
//! textmacro addreg takes i
     call RegionAddRect(r, gg_rct_ar00$i$ )
//! endtextmacro

//! set i = 1
//! textloop
    //! runtextmacro addreg(i)
    //! set i = i + 1
    //! exitwhen i > 9
//! endtextloop

Collapse JASS:
//! textmacro addreg takes i
     call RegionAddRect(r, gg_rct_ar00$i$ )
//! endtextmacro

//! textmacro times takes macro, count
    //! runtextmacro macro(count)
    //! if count > 0 then
        //! runtextmacro times(macro, count-1)
    //! endif
//! endtextmacro

//! runtextmacro times(macro, 9)
04-13-2009, 03:32 PM#9
Strilanc
Quote:
Originally Posted by akolyt0r
this solution misses an identifier for the index.

You only need an identifier when declaring the text macro, or if you wanted the same index to be used in two arguments.

Collapse JASS:
//! runtextmacro name("some_arg", 0:99, "some_other_arg")

//expands to: 
//! runtextmacro name("some_arg", "0", "some_other_arg")
//! runtextmacro name("some_arg", "1", "some_other_arg")
...
//! runtextmacro name("some_arg", "99", "some_other_arg")
As you can see, no need for an identifier.
04-13-2009, 04:15 PM#10
Seshiro
I'd say that
Collapse JASS:
//! fortextmacro(min,max,step) addreg(:iterator:)
looks for me like a good opinion^^

Greez
04-14-2009, 02:17 AM#11
Anitarf
//! runtextmacro name("meh", iterator) 1 to 5 step 2 Dunno, just a random suggestion. I don't particularly care for textmacros anyway.
04-14-2009, 02:58 AM#12
Deaod
//! for i=1 to 5 step 1 do runtextmacro addreg(i)
pascal-style!

maybe without "step 1"....
04-14-2009, 04:44 AM#13
Blackroot
Code:
//!for n=0;9
 call RegionAddRect(region, gg_rct_000$n$)
//!endloop

[edit]
endloop is probably going to be tokenized; so you'd probably need something not already taken.

or Maybe
Code:
//!do
 call RegionAddRect(region, gg_rct_000$n$)
//!for n=0;9
04-14-2009, 05:48 AM#14
Here-b-Trollz
Collapse loop(start,end,step):
//! loop(1,100,1)
    stuff
//! endloop

Expand addreg example:


Collapse Alternatively, we could define what our symbol is - loop(start,end,symbol,step):
//! loop(1,10,Q,1)
    //! runtextmacro addreg($Q$)
//! endloop

Expand Alternative keywords:
04-14-2009, 06:33 AM#15
Feroc1ty
Collapse JASS:
//! textloop addreg i(+1,00,09)
     call RegionAddRect(r, gg_rct_ar00$i$ )
//! endtextloop

Collapse JASS:
call RegionAddRect(r, gg_rct_ar0000 )
call RegionAddRect(r, gg_rct_ar0001 )
call RegionAddRect(r, gg_rct_ar0002 )
call RegionAddRect(r, gg_rct_ar0003 )
//etc...