Page 1 of 1

(wish) Replace with each replace x=x+1

Posted: Sun Jul 16, 2017 8:57 am
by Bugala
When using "replace" option in Windows IDE, I notice that it is quite usual that I am replacing something where there is number included in the replacement and then it is supposed to rise by one each time.

as example i might have:

Code: Select all

gfx["itemname1"] = 1
after which i copy paste this same line several times:

Code: Select all

gfx["itemname1"] = 1
gfx["itemname1"] = 1
gfx["itemname1"] = 1
gfx["itemname1"] = 1
gfx["itemname1"] = 1
after which i change the real names and numbers to it:

Code: Select all

["itemname1"] = 1
gfx["itemnama"] = 2
gfx["itemnamo"] = 3
gfx["itemnameas"] = 4
gfx["itemn"] = 5
It isnt that much trouble changing those numbers afterwards manually, but I was wondering how difficult would it be to make "replace" function in such way that you could determine that one of the things to be replaced is a number that rises by 1 after each click.

Re: (wish) Replace with each replace x=x+1

Posted: Mon Jul 17, 2017 6:00 pm
by SamuraiCrow
Personally, I'd prefer an actual enumeration function.

Re: (wish) Replace with each replace x=x+1

Posted: Mon Jul 17, 2017 10:36 pm
by Bugala
Im always worried of colliding with some reserved word in future when using enumerations.

Also, Tables can give some other benefits too in some more unusual cases. Like say i dont want to keep all the gfx in memory all the time but load them when needed, in this case I could remove some items from table and that way avoid them being referred to anymore. You can of course do the same with enumeration, but then it requires you to having table of which ones are available to use and which not, in which case you are anyway going to be making a table, so why not just make one right from beginning.

But especially when there are only very few graphics involved in program, enumerations is definetily the way to go.

Re: (wish) Replace with each replace x=x+1

Posted: Tue Jul 18, 2017 7:46 am
by SamuraiCrow
I would expect all the enumerations to be prefixed with a # symbol since they are constants.

Re: (wish) Replace with each replace x=x+1

Posted: Tue Jul 18, 2017 4:03 pm
by SamuraiCrow
@include enum.hws from here to add an enum class. Warning it's untested at this point but has in-code documentation and an equally untested unit test method.