Forum Discussion

Komag's avatar
Komag
Roku Guru
12 years ago

trying to print a simple array value (string), not working

This should be pretty simple:
	testArray = [X, Y, Z]
print testArray[0] ' this only prints <bsTypedValue: >

How can I get it to print out the X? What exactly is going on?
I tried:
	print stri(testArray[0]) ' error, Type Mismatch
myString = testArray[0]
print stri(myString) ' error, Type Mismatch

I also tried various versions of ToStr() such as ToStr(testArray[0]) or testArray[0].ToStr() with no luck, got dot operator error.

If my array has quotation marks it works just fine, prints X just like I want, but for some other reasons I REALLY don't want to add all the " marks to the original array
	testArray = ["X", "Y", "Z"]
print testArray[0] ' this prints X

What I really want to do is check the value, not necessarily print it, such as:
	testArray = [X, Y, Z]
if testArray[0] = X then dothisdothat

but it doesn't work. It works only like this:
	testArray = ["X", "Y", "Z"]
if testArray[0] = "X" then dothisdothat

Is there some array command to just set all the values to be strings? Or is there a way to make ToStr() or Stri() work for me?

Or if I could just know what X actually currently is (since it's apparently not a string when I don't use the "), so I can properly check for it.

4 Replies

  • "Komag" wrote:
    Related question, say I have a string "map" and I want to convert to variable map, is there a way to do this?


    No, that doesn't really make sense. Variable names are arbitrary and have no intrinsic meaning.

    "Komag" wrote:

    Basically I want the opposite of ToStr(), I want to "unstring" a string!


    That's a different question. ToStr() converts and integer to a string. ToInt() or the Stri() global function do the opposite conversion, from string to integer.

    --Mark
  • "Komag" wrote:
    later, a function calls:
    compositor.NewAnimatedSprite(j*64, i*64, theCurrentRoom[i][j].sprite)

    but this doesn't work.


    If theCurrentRoom was set equal to item after the if statement you quoted, then it should work. Can you expand on what doesn't work? The approach you're pursuing, of removing quotes from a string, is not the right direction.

    --Mark
  • I guess we'd need to see the code you're using to put your 'item' values in the 'theCurrentRoom' array to know why it's not working (the code as well as the debugger output of whatever you say 'doesn't work').
  • "EnTerr" wrote:
    It's also possible you might be asking for this as "unquoting":

    'init phase
    item = {
    name: "wall",
    blocker: TRUE,
    sprite: "sprite_brickwall2"
    }
    ...
    'peruse phase
    compositor.NewAnimatedSprite(j*64, i*64, bitmapset.animations[theCurrentRoom[i][j].sprite])


    THIS!

    You nailed it, that works perfectly!

    Basically this is a shortcut way to build a grid room layout with various sprites in various locations, based on a grid layout of 64 pixels per square, and since I'm going to have a lot of different possible items, I needed a procedural way to make it work without having to set up manually too many IF THEN specific matches.

    I had no idea that
    [theCurrentRoom.sprite]
    which is defined as a string (such as "sprite_brickwall2"), could be added after
    bitmapset.animations
    to properly access the xml file info. I probably need to study the xml syntax and controls more, I feel like I'm probably not making use of it as I should. I'm really not a programmer, but I did a Legend of Grimrock mod project with Lua last year and BrightScript feels very similar to that language.