Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use VAR more than once on the same variable (and declaring empty array) #20

Open
casson-projects-2020 opened this issue Mar 16, 2021 · 0 comments

Comments

@casson-projects-2020
Copy link

casson-projects-2020 commented Mar 16, 2021

First let me say: great project! I was searching for a way to program macros in SVG editors for ever and PSVG solves this problem for me.

I have two things to point out: when I try to execute this example (found in your docs):

  <var data="M 0 0 L 10 10"/>
  <var data="CAT(data,'L',20,10)"/> <!-- adds a new point -->
  <path d="{data}">

Chrome (version 89.0.4389.90) raises an "Identifer data has already been declared" error.

I was able to circumvent the problem, but that end up being kinda ugly :) and is the source of the second point.

I declared the variable just once and then manipulate it using dummy attributes, using javascript inside them (what I believe can be against the philosophy of the language):

  <var incs="0 0 1 1 0 0" />
  <var ps="[ ]" />
  <g style="{ps.shift(),ps.shift()}"></g>
  <for i="0" true="{i<5}">
    <g style="{ps.push((px + w * incs[ i ]) * scale, (py + h * incs[ i + 1 ]) * scale )}"></g>
  </for>

My intention was to declare an empty array and the only way I could manage it was to declare ps="[ ]" (notice that this generates and array, with the 1st element == "[" and the second == "]" :) ) and then use "shift" twice in the next line.

So my second point is: Is there a way to declare empty arrays? I've tried ps="" and then use "push", ps="[]" (but that generates a string, I think), and

  <var ps="" /><g style="{ps=[]}"></g> 

and no one of them worked.

Also it appears to me (but I can be wrong, please point it out if it is the case) that the builtins CAT, NTH and etc cannot be used inside { } in PSVG, hence the use of "push".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant