Jump to content




Controlling Turtle with local key-pressed events

turtle api

3 replies to this topic

#1 michaelcampbell229

  • Members
  • 17 posts

Posted 12 July 2017 - 06:57 AM

So I have to two scripts. One runs on a Advanced Wireless Pocket Computer and the other on a Advanced Wireless Mining Turtle.
This script runs on the turtle controls movement such as forwards, up, down, turn left, turn right, backwards, break block, and place blocks.
ComputerCode
and this code runs on the turtle. When the turtle receives a message, corresponding to the message sent dependent on a key pressed, it then moves the turtle. I haven't written the code that will actually make the turtle move (based on which options is selected) yet that that shouldn't be too hard.
TurtleCode

So, the turtle will move based on which key is pressed when the screen is showing Height, Forwards, and Back (as expected and planned) as/when variable x == 1. When the "k" key is pressed the screen clears and shows the "Controlled" screen (which that should show when the "k" key is pressed) (and if pressed again will go back to the previous screen/message) but when another key is pressed such as the programmed m key nothing is happening, should pressing the m key not print "YES" ? (and if it is changed to another key, such as l, the same result) Originally i thought that it was because there are two local events but then when on the Controlled screen pressing the k key wouldn't do anything correct?

The idea is when its in the first mode (Height ect) the user can manually control the turtle, when they press k (probably should make it k and something else, but that is easy) the robot goes into "Programmed/Controlled" mode, the user then selects an option such as: option a: dig 16x16x1 meaning that rather than the user having to manually control the robot to dig out area they put it in programmed mode and off it goes based on controls stored/programed on the turtle; but I have hit this wall and I cant progress until this bit is fixed.

Something like this would replace the part that currently says "YES": (this includes the option a, option b, and option c bit) (this bit of code is not tested just an idea as I haven't been able to get past this bit so ignore any code errors in this part)
CodeTheory - read after


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 July 2017 - 01:33 PM

Pressing 'm' does print "YES". However, let's take a look at the sequence of events

-screen is cleared
-cursor set
-"controlled" written
-"m" is pulled as an event
-"YES" is printed
-screen is cleared
-cursor set
-"controlled written"
-waits for another event.

#3 michaelcampbell229

  • Members
  • 17 posts

Posted 13 July 2017 - 04:02 AM

View PostKingofGamesYami, on 12 July 2017 - 01:33 PM, said:

Pressing 'm' does print "YES". However, let's take a look at the sequence of events

-screen is cleared
-cursor set
-"controlled" written
-"m" is pulled as an event
-"YES" is printed
-screen is cleared
-cursor set
-"controlled written"
-waits for another event.
Thanks for your response, so it is displaying yes but it is then instantly cleared and "controlled" is then displayed again. Ok thanks, I'll try modify the code so it doesn't look like that, any suggestions that would still provide the functionality that I am trying to achieve?

#4 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 13 July 2017 - 11:45 AM

Clear the screen after pulling the event but before printing yes (or doing any other event processing which uses the screen)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users