How do I get value between characters and loop

Get help using Construct 2

Post » Sat Feb 20, 2016 4:42 pm

With the help of R0J0hound I made a script that reads SVG polygon coordinates and creates a terrain.

Currently it reads it from a .txt file (using tokenat() and creating loop for each shape) which has to be manually populated with information. I was wondering if this step can be eliminated and improve the workflow. However to read directly from the SVG file it needs to get the coordinates in between characters and create a loop.

For example this is an SVG code

Code: Select all
<polygon class="st0" points="1520.4,280.6 1456.7,280.6 1456.7,339.7 1527.7,339.7 1527.7,357.4 1435.5,357.4 1435.5,193.5
   1524.1,193.5 1524.1,211.3 1456.7,211.3 1456.7,263.1 1520.4,263.1 1520.4,280.6 1520.4,280.6 1520.4,280.6 "/>
<polygon class="st0" points="1550.3,345 1550.6,341.9 1551.4,339 1552.7,336.4 1554.4,334.2 1556.5,332.4 1558.9,331.1
   1561.7,330.2 1564.7,329.9 1567.8,330.2 1570.6,331.1 1573,332.4 1575.1,334.2 1576.8,336.4 1578,339 1578.7,341.9 1579,345
   1578.7,348.1 1578,351 1576.8,353.5 1575.1,355.8 1573,357.6 1570.6,358.9 1567.8,359.8 1564.7,360.1 1561.6,359.8 1558.8,358.9
   1556.4,357.6 1554.3,355.8 1552.6,353.5 1551.3,351 1550.6,348.1 1550.3,345 1550.3,345 1550.3,345 "/>
<polygon class="st0" points="1556.4,310.2 1553,193.5 1576.3,193.5 1572.9,310.2 1556.4,310.2 1556.4,310.2 1556.4,310.2 "/>


So it needs to - for each <polygon> get coordinates between points=" and ", and create for each loop.

My question is how to get the value between points=" and "? Is there a system function that can do that (something like PHP's preg_match() maybe)?
Ba-dum Tsss!
B
11
S
2
G
1
Posts: 45
Reputation: 757

Post » Sat Feb 20, 2016 5:56 pm

tokenat()

https://www.scirra.com/manual/126/system-expressions


Use nested tokens, first one would be for polygon, second one would be for points, third one for commas.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Feb 20, 2016 6:49 pm

You probably should be able to use the xml plugin to do this. Take a look at it, it has methods to loop over tags and such.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Sat Feb 20, 2016 8:45 pm

I'm a huge dum-dum... there're regular expression functions - RegexMatchAt(), RegexMatchCount(), etc.

@oosyrag tokenat() uses separator to create keys, I need to get the value in between given characters (what regular expressions do)
@R0J0hound I checked it out, but I'm not quite sure how to work with XML files and this plugin in particular. I think the functions I mentioned above would work in this case.

Thanks for the suggestions!
Ba-dum Tsss!
B
11
S
2
G
1
Posts: 45
Reputation: 757


Return to How do I....?

Who is online

Users browsing this forum: Kermad, lukewasthefish, marc254, tarek2 and 15 guests