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

If String contains

Started by Alexander0507, 01 January 2014 - 05:42 PM
Alexander0507 #1
Posted 01 January 2014 - 06:42 PM
Is there a easy way to make a statement like : If string contains "…" then ?
CometWolf #2
Posted 01 January 2014 - 06:46 PM
if stringName:match"whatever you want it to contain" then
Alexander0507 #3
Posted 01 January 2014 - 06:51 PM
I get attempt to call nill at line 11: http://pastebin.com/6UhrxPVG
CometWolf #4
Posted 01 January 2014 - 06:59 PM
Because cell1 is not a string

local cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_0")
Does not return a string, but rather a table. Thus you are not calling the string function when you do cell1:match"".
Alexander0507 #5
Posted 01 January 2014 - 07:04 PM
Is there a way to get around this ?
CometWolf #6
Posted 01 January 2014 - 07:07 PM
Not entirely sure what you're trying to do there, as you already know what peirpheral is wrapped to cell1, no?
Alexander0507 #7
Posted 01 January 2014 - 07:08 PM
I want it to check if cell1 is the energycell then execute the addBox-stuff else just skip it
CometWolf #8
Posted 01 January 2014 - 07:11 PM

if cell1.getEnergyStored then
Should check wether the table the cell is wrapped to, contains an energy cell function. If it does not, it's not an energy cell.

it is quite redundant however, as no other peripheral would have the same name, meaning your wrap would fail anyways if one wasn't connected.
Edited on 01 January 2014 - 06:12 PM
Alexander0507 #9
Posted 01 January 2014 - 07:12 PM
Ahh it works :D/>
Alexander0507 #10
Posted 01 January 2014 - 07:20 PM
But now I get line 10 or 28: attempt to index dependend on which is connected
But is should just skip this part of the code .

Edit: solved the problem by myself. using peripheral.isPresent(peripheral-name)
Edited on 01 January 2014 - 07:04 PM