HscriptFAQ

From Odwiki

Jump to: navigation, search

HScript Frequently Asked Questions

Does HScript support Arrays?

  • Not directly, but if your strings have no spaces in each token, then you can use one long string and pull out an "element" using arg().
    #set values
    set var = ""
    for i = 1 to 10
      set var = "$var `string$i`"
    end
    # now print out all values
    for i = 1 to `argc($var)`
      echo `arg($var,$i)`
    end
  • Note: It's also possible to have spaces in your elements as long as you enclose them in double quotes. The arg() function will keep strings which are quoted together.
         -> set a = '"hello world" "how many" arguments "are here"'
         -> echo `argc($a)`
         4
         -> echo `arg($a, 0)
         hello world
         -> echo `arg($a, 3)
         arguments
  • Also, here's an arcane form of variable expansion which can be used to simulate arrays.
    #set values
    for i = 1 to 10
      set var$i = `rand($i)`
    end
    # now print out values
    for i = 1 to 10
      echo ${var$i}
    end


The contents of the {} are expanded and used to form the variable name for the other $ expansion.

This is in hscript of course... You might be able to use these in expressions, though probably in a limited sort of fashion.

© 2009 od[force].net | advertise