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

string issues (advanced and wierd)

Started by mrgreaper, 26 November 2013 - 09:42 PM
mrgreaper #1
Posted 26 November 2013 - 10:42 PM
ok im so confused i dont even know what o al this issue let alone what to google to fix it!

so heres the bit of problem code that im working on


function missileselect(silo) --recieve the silo number the loadmissile() function
print (silo)
silos = ("silo"..silo.."int")
print (silos)
-- silo1int4 = silos   --this does not work even though the value of silos is silo1int
silo1int4 = silo1int --and yet this works!?!?!?!?
datatable1= silo1int4.getStackInSlot(5)

ok so when the function is called it is called with a number and silo is given that number
all my silos are mounted as siloXint where x is the number 1 to 6
so ets say we called it with missileselect(1)
then silo = 1
so silos becomes silo1int
this all works and is fine BUT
if i attempt to have silo1int4 = silos then the line database1=silo1int4.getStackInSlot(5) errors out (yes i know i should be able to skip the silo1int4 bit, its just the way i was ruling out other stuff)

now if i silo1int4 = silo1int then the database line works perfectly

i can work around this of course with some if / elseif statements but i want to know why silos which equals the same as silo1int doesnt work

is it perhaps actualy "silo1int" instead of silo1int and if so is there a way i can turn it from the ""version to the none "" version

ok i have explained as well as i can do, but i have no idea what to look for to google this issue away (i have looked at strings gusb functions in strings taking parts of strings …i have gone cross eyed
ebernerd #2
Posted 26 November 2013 - 10:48 PM
One thing I noticed (and it may be becuase you forgot to copy and paste) is that you dont have an end. Try that.

What i mean is an

function(derp)
code
end -- <THAT

Also, Where it says "print(silos)" Silos is not a variable you created. Silo is, though.
ElvishJerricco #3
Posted 27 November 2013 - 03:11 AM
Your problem is that you're expecting a string "a" to translate to the value in variable a.

a = 4
b = "a"
c = b
print(c)
You'd expect this to print a, not 4. print© translates to print(B)/> which translates to print("a") which prints the character 'a'. You need to switch off of using statically defined names when you want to dynamically access them. The best way to do this by far is through tables. Instead of silo1int (weird naming convention, btw), use something like silos[1] and databases[1].
mrgreaper #4
Posted 27 November 2013 - 09:28 AM
One thing I noticed (and it may be becuase you forgot to copy and paste) is that you dont have an end. Try that.

What i mean is an

function(derp)
code
end -- <THAT

Also, Where it says "print(silos)" Silos is not a variable you created. Silo is, though.

its a part of the code, trust me its ended correctly. silos is a variable thats created see line 3 :)/>
Your problem is that you're expecting a string "a" to translate to the value in variable a.

a = 4
b = "a"
c = b
print(c)
You'd expect this to print a, not 4. print© translates to print( B)/> which translates to print("a") which prints the character 'a'. You need to switch off of using statically defined names when you want to dynamically access them. The best way to do this by far is through tables. Instead of silo1int (weird naming convention, btw), use something like silos[1] and databases[1].

I tried tables it went horribly wrong but i think i now know why i, tried

table = { "silo1int","silo2int","silo3int"}

when i think i should of done


table = {silo1int, silo2int, silo3int}

will try the above in a few minutes (need food first lol)

The naming convention will make sense when i share the whole program :)/>
theres 6 silos each with a launcher and an interface the launchers are wrapped as silo1-6 and the interfaces are wrapped as silo1-6int :)/>

edit yep now im not putting "" around them in the table they work great WOOO! :)/> thank you
Edited on 27 November 2013 - 10:59 AM