SA-MP Forums Archive
How to define foreach function for new version - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to define foreach function for new version (/showthread.php?tid=661390)



How to define foreach function for new version - StRaphael - 02.12.2018

Hello, I am trying to update my YSI includes and I got some warnings 'like warning 219: local variable "using_deprecated_foreach_syntax" shadows a variable at a preceding level'
My question in how to define Foreach(Player, i) to Foreach(new i : Player)?Is this possible?
I tried this:
#define foreach(%0, %1) foreach(new %1 : Player) but don't work. I have to define it becouse my gamemode doesn't called all variables "i".
Thanks in advance


Re: How to define foreach function for new version - StRaphael - 02.12.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
You need to replace the (10 year) old code with the new version. The variable name doesn't matter.
I did it in a hour(hoped to find an easy way than to use Replace All editor function for each changed variable than "i")
anyway thanks
rep


Re: How to define foreach function for new version - StRaphael - 03.12.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
regex replace?

foreach\s*\((\w+),\s*(\w+)\)

foreach(new $2 : $1)
Oh, thank you, you saved my time
I really didn't knew about regular expressions and regex replaces until now
Thanks again!

But I have a (small) problem:
when I replace with my edtitor with this code, it replaces without round brackets(foreachnew i : Player)
I use notepad++ editor. Can be an editor bug or smth?