1. #1
    New Member Follow User Gallery
    Join Date
    Jul 2017
    Posts
    13

    Default Array utils

    Hi all,

    I am coming from pythonic root and am trying to initialize, append, and loop though arrays/lists. I struggled to find docs other than the official site as array and list are common terms for other objects on threads. I've seen this in the documentation:

    http://docs.pixologic.com/user-guide...ing/technical/

    """
    ZScript provides for arrays of strings or numbers. The declarations are simple:

    [VarDef, gValues(9), 3] creates an array ‘gValues’ of 9 numbers, each initialized to 3.
    [VarDef, gWords(5), "Hello"] creates a three element array of strings, each initialized to “Hello”. Array element are accessed starting from 0; myArray(0) is the first element of myArray, myArray(1) is the second element, and so forth. (This is standard use for arrays in most programming languages.)
    """

    I dont want consecutive ints though, I want the list to be able to hold strings and another to hold variables. Is there way to initialize a list with several strings or vars? i.e. listX = ["A", "B", "C"]

    Is there a way to append strings and vars to an existing list? i.e. listY.append(newSubtoolName)

    And the next step would be looping through an array.
    [Loop, listX,
    [IPress, x]
    ,x]

    If we cant do that can we check the number of items in an array - len(listX) so that we can do something like this:
    listXLen = len(listX)
    [Loop, listXLen,
    [IPress, listX(x)]
    ,x]

    Thanks!

  2. #2
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    I'm afraid zscript is pretty basic compared to other scripting languages and you simply can't do directly what you outline.

    Arrays are declared fixed size, so you'd need to create them large enough and then keep track of their 'size'. You can only fill them with integers/floats or strings.

    You can declare a list of empty strings:

    [VarDef,myStrList(100),""]//max number of elements

    Then loop through the list:

    [Loop,[SubToolGetCount],//loop through all subtools
    [SubToolSelect,n]
    [VarSet,myStrList(n),[IGetTitle,Tool:Current Tool]]
    ,n]

    would fill the [SubToolGetCount] number of elements of the list and where 'n' is the loop counter variable.

    For concatenating strings you need to use [StrMerge].

    HTH,

  3. #3
    Senior Member Follow User Gallery
    Join Date
    Feb 2015
    Location
    Paris
    Posts
    263

    Default

    just to complete with what Marcus told you already
    you can store any types of values (int,float,bool, strings) within a varlist if you declare it this way,
    [VarDef, varlist(99), ""]
    Plugins & Toolsets for Zbrush 4R8 : zCycler Pro | Plugin Manager |Matiere 3d | Twitter | @Facelessmindz

  4. #4
    New Member Follow User Gallery
    Join Date
    Jul 2017
    Posts
    13

    Default

    Thanks for the info! Sorry, I may have missed this part but if I declare an array

    [VarDef,myStrList(100),""]//max number of elements

    can I then add a string/replace myStrList(1) with "SubtoolnameA"?

    or can I declare a list
    [VarDef,myStrList(2),"X, Y"]

  5. #5
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    [VarDef,myStrList(100),""]//max number of elements

    can I then add a string/replace myStrList(1) with "SubtoolnameA"?
    Yes, you can set (or reset) any of the elements like this:

    [VarSet, myStrList(1), "SubtoolnameA"] //change second variable in the list to "SubtoolnameA"

    or can I declare a list
    [VarDef,myStrList(2),"X, Y"]
    No, you can't use that syntax. (At least, it won't do what you want - you'll create a list with both elements set to "X, Y")

  6. #6
    New Member Follow User Gallery
    Join Date
    Jul 2017
    Posts
    13

    Default

    Great, thank you for the info!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •