This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
westloar's profile picture

Changing a string to a name

Started by westloar, 28 July 2015 - 07:33 PM
westloar #1
Posted 28 July 2015 - 09:33 PM
Is there any method to change a string into a name (as defined by colors api)?

I have the following table and wish to change the color of text based on an entry in this table:


colTab = {"red","white","orange","magenta"......}

term.setTextColor(colors.colTab[1])

This returns an error stating that it was expecting a name for the colors argument.

I have looked at different ways to manipulate strings and I cannot find a method to solve this, I could create a multi-dimensional table that includes a color number for each entry, however I would prefer the table to remain as it is.

Any help or pointers would be appreciated.
HPWebcamAble #2
Posted 28 July 2015 - 09:49 PM
You are close, but you index the table slightly wrong:


colors[ colTab[ 1 ] ] --# This should be correct

This:

tableName[ "indexName" ]
is the same as

tableName.indexName

So this:

colors.colTab[1]
is the same as

colors[ "colTab" ][1]
Edited on 28 July 2015 - 07:50 PM
westloar #3
Posted 28 July 2015 - 10:06 PM
Thankyou very much for my help, that fixed it! I probably wouldn't have worked that out by myself.