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

shell.getRunningProgram Help!

Started by dexter9, 28 February 2013 - 07:32 AM
dexter9 #1
Posted 28 February 2013 - 08:32 AM
Hi,
im trying to get a turtle to do shell.getrunningprogram( i think this tells it what program is currently running…) but it wont work. How do i display the info it has gained by running this command during my program?
KaoS #2
Posted 28 February 2013 - 08:38 AM
try just print(shell.getRunningProgram()) and it should print the running program. please not the capitalization on the R and P. important
dexter9 #3
Posted 28 February 2013 - 08:40 AM
I thought you need it?…..
OmegaVest #4
Posted 28 February 2013 - 08:41 AM
I think he meant "do not forget" to capitalize.
dexter9 #5
Posted 28 February 2013 - 08:43 AM
Ok works. Just not the way want it to….. As i said i run all that from a program and then i run a program inside the same program ie.dance. My program is called turtle. It says i am running turtle. how do i get it to say dance?

same. but i trust other people more than myself :L
OmegaVest #6
Posted 28 February 2013 - 08:53 AM
… First off, I think it is a bad idea to call a program "turtle", but whatever. Secondly, in what program are you calling getRunningProgram? Because wherever you call it is where it will get the name from.

If you are calling it in turtle, it will always return turtle.

I would tell it which program is running. ie. tab[2] = "dance", and then when the remote asks, send back tab[2], or a list of tabs. But, that's me, and very brute-force, so to speak.
dexter9 #7
Posted 28 February 2013 - 08:55 AM
Yeah never really thought about that…… i call it in turtle and could you explain your resoloution better.
OmegaVest #8
Posted 28 February 2013 - 08:58 AM

tab = {}
tab[0] = "turtle"

function dance()
tab[#tab+1] = "dance"
shell.run(dance)
end


Or however you run it. If you are paralleling, you can use multiple "tabs" to keep track of what you are doing, and send them off with a simple call.
I'd explain more, but I'm late for a meeting.
dexter9 #9
Posted 28 February 2013 - 09:24 AM
Ok thanks thats helped!
dexter9 #10
Posted 01 March 2013 - 08:03 AM
If you find the chance could you explain this better how it works. I dont like including stuff if i dont actually know how it works and how i can adjust it best…
dexter9 #11
Posted 01 March 2013 - 09:07 AM
Where does this code go?
OmegaVest #12
Posted 01 March 2013 - 10:51 AM
Hrm. Okay, so the code fragment I gave you was mostly just an example.

However, I don't really know how your governing program is set up. If I knew what that looked like, I might be a bit more help.
dexter9 #13
Posted 02 March 2013 - 05:47 AM
Yes i realise this is an example. I mean does it go at the very start with the locals and before the "while true do" or does it go whenever im trying to run that certain program? I dont really like using pastebin :L
OmegaVest #14
Posted 02 March 2013 - 08:46 AM
Ahm, well, the idea is that you would set the tab table up at the start and add your governing program to it. Then, whenever you call another program, add an index to tab. When the program finishes, remove that index.

Really, this is the same way shell handles the getRunningProgram function, so it's kinda a bad extension to it. Something akin to adding a 2x4 to the side of another 2x4 to give it extra length.



EDIT: Also, I just realized my code is broken. dance should always have quotes around it.
dexter9 #15
Posted 02 March 2013 - 08:58 AM
When you say index what do you mean? And i realised that…..
OmegaVest #16
Posted 02 March 2013 - 09:03 AM
Index: the number (or string, character, object, etc) you use to identify where in a table to look. It can also refer to the "slot" the index signifies. So, adding or removing an index just means to extend or shrink the table.
dexter9 #17
Posted 02 March 2013 - 09:04 AM
Ok can you give me an example is it like function dance() (dont even know if thats right)
dexter9 #18
Posted 02 March 2013 - 10:04 AM
Okay worked it out myself. It shows now rom/programs/turtle/dance im guessing this is normal. How can i get it to just say dance?
dexter9 #19
Posted 03 March 2013 - 04:53 AM
The information that the turtle gets is then forwarded on to a PC. It shows function: 8fb057 . How do i translate this to words as in "dance"?
ChunLing #20
Posted 03 March 2013 - 05:55 PM
Code.
dexter9 #21
Posted 05 March 2013 - 06:27 AM
obviously though can you help/direct me to fixing this?
OmegaVest #22
Posted 05 March 2013 - 12:30 PM
Okay, so I'm gonna give you as much help as I can, because I finally figured out how to put it, and I hope you know how to implement it.

Basically, you are returning the function itself, not the name of that function. So, there's no way to get the name from the number.
theoriginalbit #23
Posted 05 March 2013 - 01:04 PM
Ok works. Just not the way want it to….. As i said i run all that from a program and then i run a program inside the same program ie.dance. My program is called turtle. It says i am running turtle. how do i get it to say dance?
This is why it doesn't work.


print(shell.getRunningProgram()) -- prints turtle, as thats the program you're in
shell.run("dance") -- run the dance program
print(shell.getRunningProgram()) -- prints turtle, as thats the program you're in, dance has finished running.

EDIT: Also, I just realized my code is broken. dance should always have quotes around it.
Also tab[0] should error too, since indexes are 1+

Really, this is the same way shell handles the getRunningProgram function, so it's kinda a bad extension to it.
Not really… the shell api has access to the debug api, so that means it can directly access the program stack, unlike our programs. The best that we can do is to create our own artificial program stack, which requires a bit of work. but you used the example of a table called tab, when i made a stack for CCTube I called it stack :P/>


local stack = {}

function push( val )
  table.insert( stack, val )
end

function pop()
  if #stack == 0 then return end
  stack[ #stack ] = nil
end

function printStackTop()
  print( stack[ #stack ] )
end
just means that in the programs code you need to do this everywhere

local function someFunction()
  push('someFunction')

  -- code in here

  pop()
end

local function anotherFunction()
  push('anotherFunction')

  -- code here

  pop()
end

push('running dance')
shell.run('dance')
pop()