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

Updater Help

Started by Zenon, 21 July 2015 - 05:33 PM
Zenon #1
Posted 21 July 2015 - 07:33 PM
Hi all! Making an updater (as you might have seen in my last post) and am just wondering why this isnt working. Code:
Spoiler

local name = {...}
program = name[1]
function update()
shell.run("pastebin", "run", "GVZYhGTS")
print(tostring(program[1]))
if program[1] == true then
  shell.run("pastebin", "get", program[2], "updatetest")
end
end
update()

But it works if I do this:
Spoiler

function update(program)
shell.run("pastebin", "run", "GVZYhGTS")
print(tostring(program[1]))
if program[1] == true then
  shell.run("pastebin", "get", program[2], "updatetest")
end
end
update(enderdice)

Here is the pastebin its running

Any help is appreciated, because I cant really think of any reason why it wont work :P/>
Thanks in advance!
Edited on 21 July 2015 - 05:33 PM
KingofGamesYami #2
Posted 21 July 2015 - 08:48 PM
Is there an error, or does it do something you don't want it to? Please be specific in describing what you want to happen and what does happen.
Zenon #3
Posted 21 July 2015 - 09:13 PM
Is there an error, or does it do something you don't want it to? Please be specific in describing what you want to happen and what does happen.
No error, just doesnt work . . . Though where it prints it says nil, which leaves me to believe its trying to print the table program[1] instead of the input table, although if I use the second code it will use the input table (Im describing that horribly, though hopefully you understand it)

Edit: As for what I want to happen:
I want to use this program by using shell.run, with a singular arguement:

shell.run("themccm/updater", <insert program>)
I want to do this so I can run the program within a program, or seperately, and update the program without having to make a seperate updater for each program.
Edited on 21 July 2015 - 07:32 PM
MKlegoman357 #4
Posted 21 July 2015 - 09:43 PM
If you're running the program with shell.run or through an actual shell all the passed arguments will be strings. Now here:


local name = {...}
program = name[1]

the 'program' variable holds the first argument passed to the program. So if I run the program like so:


# through the code:
shell.run("updater", "my_super_program")

#or through the shell:
> updater my_super_program

the 'program' variable ends up with a string value "my_super_program". After that you try to index that string with the number key '1':


print(tostring(program[1]))

and then with the number key '2':


shell.run("pastebin", "get", program[2], "updatetest")

I don't know what you are expecting to find after indexing a string with those keys, but you can be sure that they will be nil.
Zenon #5
Posted 21 July 2015 - 10:30 PM
If you're running the program with shell.run or through an actual shell all the passed arguments will be strings. Now here:


local name = {...}
program = name[1]

the 'program' variable holds the first argument passed to the program. So if I run the program like so:


# through the code:
shell.run("updater", "my_super_program")

#or through the shell:
> updater my_super_program

the 'program' variable ends up with a string value "my_super_program". After that you try to index that string with the number key '1':


print(tostring(program[1]))

and then with the number key '2':


shell.run("pastebin", "get", program[2], "updatetest")

I don't know what you are expecting to find after indexing a string with those keys, but you can be sure that they will be nil.
Ohhh I didnt realize it was making it a string . . . Do you know a way to "unstring" a string? Or would I be better off doing what Im doing in a different way?
Bomb Bloke #6
Posted 22 July 2015 - 01:42 AM
Er, instead of doing that, would you not just want to do something like this?:

print(program)

shell.run("pastebin", "get", name[2], "updatetest")
Zenon #7
Posted 22 July 2015 - 02:07 AM
Er, instead of doing that, would you not just want to do something like this?:

print(program)

shell.run("pastebin", "get", name[2], "updatetest")
WOW I feel like an idiot. Thanks Bomb Bloke, youre always helpful :P/>