computercraft, quick question.

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Edit: figured this out but have a new question below.

Here there I am a newb when It comes to computer craft and just wrote a small program but once I start the program How can I stop it without breaking and replacing the turtle so I can enter code into the turtle again?

I tried hitting Ctrl + T, Ctrl+R & Ctrl + S.. None of them seem to do anything..

Basically I made a Xpturtle and wrote a simple script to collect xp near it every 4 seconds. After Its done tho I need to be able to use some commands in the lua prompt to make use of that xp i collected. And if I just break the turtle & replace it I loose the xp.

Thanks.
 

Bibble

New Member
Jul 29, 2019
1,089
0
0
To terminate a program, it's Ctrl+T, to restart the turtle, it's Ctrl+R.

However, these aren't queued. You need to press and hold until the desired action happens (that be had me for quite a while).
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
To terminate a program, it's Ctrl+T, to restart the turtle, it's Ctrl+R.

However, these aren't queued. You need to press and hold until the desired action happens (that be had me for quite a while).

LOL so simple yet so hard... I would have never thought to actually hold the keys in.. I was just hitting them like you would normally do.. Thanks a ton haha
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Ok another question if anyone can answer this. I want to first off say that I am VERY new to turtles. the only program I have written so far was the basic while true do attack blah blah.. I do understand variables and functions and things to a certain extent tho.

I want to have my xp turtle automated so that he is placed in my mob farm the attack turtle kills the mobs and the xpturtle sucks up the xp and when he gets 30 xp he gets a book from the chest and enchants it..

The two functions the XpTurtle adds that I will use are collect (collects xp from the ground around the turtle), getlevels( Gets the number of levels the turtle has stored.), & enchant(levels) which enchants an item in the first slot.

So I was going to try to make a script to collect the xp and then do a getLevels() and if that equals 30 it would enchant a book in the first slot with those 30 levels.

One issue is tho that you can only have 1 book in the slot to enchant it you cant have say a stack of books in the slot.

And If I was to say get the books from a chest using the turtle.suck it would take a stack and put them in the 1st slot (as far as I know you cant have it only suck 1 of the item).I guess I could do a turtle.getItemCount(1) and have then turtle.transferTo(2) somehow. But how would I have it figure out how many to move.??

Can anyone think of a good way to do this?

I don't want you to write the code out for me I want to figure that out myself but I could really use help on what the best way to do what Im trying to do would be..Like is there simpler way to use the core functions to accomplish what Im trying to do or some functions that would help that Im missing?

Thanks
 

Bibble

New Member
Jul 29, 2019
1,089
0
0
I think you're on the right path. If you have the turtle suck a stack into one slot, move one of those into another slot, and put the rest of the stack back, then it should be able to enchant, and sort itself out quite happily.
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
Basically, it was implemented so it would be like when you need to make a hard stop on your computer, 5 seconds on the power button.

It allows it not to conflict with the programs that read the inputs, for example.
 

dc0110

New Member
Jul 29, 2019
123
0
0
maybe a little over complicated, but could a turtle retrieve the book from an auto crafting table?
Therefore one at a time
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
maybe a little over complicated, but could a turtle retrieve the book from an auto crafting table?
Therefore one at a time

Hmm good question .. I "Think" that only buildcraft pipes can pull out of a autocrafting table right?

I was basically trying to make this as simple as possible machine wise and do most of the work with the turtles code and use this as a way to learn computercraft in a way since I am really new to any type of programming.

I'm going to try some things, If anyone has any more suggestions please feel free to reply.

thanks
 

dc0110

New Member
Jul 29, 2019
123
0
0
crafting turtle? :)

I like the idea of turtles, but have no clue where to start
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Ok well I got the code to get the books from the chest and and then transfer 1 book to slot 2 and dump the rest of the books back to the chest from slot 1 and then move the single book to slot 1.. That seems to work great.

Now I just need to figure out how to tell it to enchant only when the levels are 30..

I guess something like the code bellow ?? ( this might be written wrong I still have to go over if,then,else statements tutorial again. )


Code:
if m.getLevels() == 30 then
  m.enchant(30)

I'm trying to learn this as I go so it would help me if you mentioned like hey if statements arnt worded like that they work this this.... But please don't do something like write the whole code for me. A section of code is fine tho :)
 

Bibble

New Member
Jul 29, 2019
1,089
0
0
Out of interest, what happens when it fails to enchant? If it just returns a false, then you could switch it to a loop of something like:
Code:
 while boo == false do
boo = m.enchant(30)
sleep 5
done

That'll just keep trying to enchant until it succeeds.
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Out of interest, what happens when it fails to enchant? If it just returns a false, then you could switch it to a loop of something like:
Code:
 while boo == false do
boo = m.enchant(30)
sleep 5
done

That'll just keep trying to enchant until it succeeds.


Yah when it fails it just returns false. Thanks, ya I didn't think about doing it like that hmm.

so boo is a variable for the result of n.enchant? sorry still trying to learn more about variables & Statements and how you can use them.

I also need to find a way to work that into the code with the rest of the stuff maybe put the enchant part into a function? can i do that..
 

Bibble

New Member
Jul 29, 2019
1,089
0
0
Yeah, boo is a variable (I wasn't feeling particularly imaginative :) ). That loop is designed as a kind of latch, assuming that you put everything in place for the enchanting first, then get to that bit, and it just runs until it succeeds. You could add a collect statement in there, too, to keep it gathering xp while it's waiting.

So, the entire script would run something along the lines of:
Code:
while true do
get a single book
select the right slot
while enchanted == false do
enchanted = m.enchant(30)
m.collect()
sleep 10
done
put book away
done

That will loop through the process of getting the book, enchanting it and putting it away before getting a new one.
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Yeah, boo is a variable (I wasn't feeling particularly imaginative :) ). That loop is designed as a kind of latch, assuming that you put everything in place for the enchanting first, then get to that bit, and it just runs until it succeeds. You could add a collect statement in there, too, to keep it gathering xp while it's waiting.

So, the entire script would run something along the lines of:
Code:
while true do
get a single book
select the right slot
while enchanted == false do
enchanted = m.enchant(30)
m.collect()
sleep 10
done
put book away
done

That will loop through the process of getting the book, enchanting it and putting it away before getting a new one.

does the code work like that eith the ends? does one of the ends at the bottom count for the top while true do? other wise doesnt there need to be an end for each while or if etc

The thing is there is no way that I can see to have it only suck up 1 book so I have the first part of the code like:
( So it grabs a stack of books or howevery many are in the first slot of the chest and puts them into the turtles 1st slot then moves 1 of those books to turtles 2nd slot and dumps the extra books back into the chest and moves the single book back to slot 1 to prepare it for enchanting.

Code:
while true do
  turtle.suck()
  turtle.transferTo(2,1)
  turtle.drop()
  turtle.select(2)
  turtle.transferTo(1,1)
  turtle.select(1)
end

SO I gota figure out how to put the two pieces of code together, If I just put the enchanting part after my code it will just loop the book part. I need to figure out how to get it to do the book part and then wait until it enchants the book and puts it into the cheast before it does the book part again.

Gimme some tips here just dont write all the code out for me tho :) ..
 

zilvarwolf

New Member
Jul 29, 2019
541
0
0
Don't forget you can set a turtle to autocollect the xp.

My version of this code relies on having an excess of books in slot 16 (because I don't let it run full time, I just put books in when I need them). The turtle is set with its back to the spawner and facing a chest in front of it.

so we have this as the basic pseudocode

register the peripheral
enable autocollect

loop forever
sleep for a few seconds
if you have 30 or more levels
transfer 1 book from slot 16 to slot 1
abort the loop and exit if there are no books in slot 16
enchant the book with 30 levels
attempt to place the book into the chest in front of the turtle
abort the loop and exit if the chest is full

It probably requires more manual intervention than many people care for (books in chests, manually putting blank books in slot 16 every day or two), but it works well for the level of enchanting I was trying to do.

(Still took me 2 days to get enough repair books to have a full set of self-repairing armor and gear :) )
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
(Still took me 2 days to get enough repair books to have a full set of self-repairing armor and gear :) )

Haha ya thats kinda the purpose of this Im trying to make the switch to uber enchanted thaumcraft tools and ditch the drill & saw and need for the lap pack but after manually enchanting the stuff and standing there for 30 levels of xp and doing it all over again it got old. Plus I see this as a good way to start learning some computercraft and in turn learn some lua programming.


Maybe I am being to picky trying to have it pull from a chest I mean I can fit a stack of books into a slot and I cant see me using a stack up very fast. Maybe I will just try to get code working that doesnt need to pull from a chest first and then once I figure that out advance to fully automating it.
 

Bibble

New Member
Jul 29, 2019
1,089
0
0
Sorry, teach me for posting code blind. Replace the "done"s with "end.

The two grab and select lines could just be substituted for the code you put there.

Did you intend to put it in a while loop? As you posted it it'll:
1. Pull a stack
2. Move one to slot 2
3. Put the stack back
4. Put the single one back in slot 1
Then go back to pulling a stack and keep repeating until you stop it.
 

Jeff Fisher

New Member
Jul 29, 2019
316
0
0
Sorry, teach me for posting code blind. Replace the "done"s with "end.

The two grab and select lines could just be substituted for the code you put there.

Did you intend to put it in a while loop? As you posted it it'll:
1. Pull a stack
2. Move one to slot 2
3. Put the stack back
4. Put the single one back in slot 1
Then go back to pulling a stack and keep repeating until you stop it.


Yah I figured that I would have to put the whole thing into a loop and that part of the code would be first.. Can you put a while loop inside a loop? I've never programmed before like I said im learning as I go. I did do some research but the extent of my programming with anything is some autoit macros lol.
I figured I could put the whole code into a loop and it would start at the beggining of the code and read down until it hit the enchanting loop and repeat only that part until it succeded enchainting then put the book back and repeat the whole loop.