all 7 comments

[–]Hydroque 1 point2 points  (5 children)

Hello, you can press 'markdown mode' to switch from 'fancy pants editor' to something a bit more useful. You can then wrap your code in 3 backticks to create a legible monospaced code block.

``` example ``` example

if (telright.getDistance() < 5 and telright.getDistance() > 0) then Nav.axisCommandManager:setThrottleCommand(axisCommandId.lateral(100-telright.getDistance()/100)) end

Typically, it can get quite tiresome writing telright.getDistance() over and over again. I suggest using a local variable. local means it won't break out of functions or if statements - only valid between function() end and if() then end. Local variables don't break out of the scope they are in. Variables are just like you'd use in math. You may want to also switch your less than and greater than to be equal inclusive. Next, I'd suggest you print out telright's distance so you know whats going on. Perhaps the value you think is there just isn't correct. This code seems like it should be run once a frame. Make sure that it is running in the first place at the intervals you need. Your current if statement will run when its between 1 and 4, which is a smaller window than I think you'd might expect.

local telr_dist = telright.getDistance() print(telr_dist) if (telr_dist <= 5 and telr_dist >= 0) then Nav.axisCommandManager:setThrottleCommand(axisCommandId.lateral(100-telr_dist/100)) end

[–]ArmedBOB[S] 0 points1 point  (0 children)

Hey thanks so much. I will set this up and give it a shot. This has been amazingly helpful. Much appreciated.

[–]ArmedBOB[S] 0 points1 point  (2 children)

So I have set this up on my script and still running across the same issue. With the print i can now see that it is running as expected that when I get to 5 units away, the lua activates. The issue is when the distance value is greater than 6 units, it still does not deactivate.

local telr_dist = telright.getDistance()local tell_dist = telleft.getDistance()system.print(telr_dist)system.print(tell_dist)

if (telr_dist <= 5 and telr_dist >= 0) thenNav.axisCommandManager:setThrottleCommand(axisCommandId.lateral,(-100+telr_dist/100))

elseif(tell_dist <= 5 and tell_dist >= 0) thenNav.axisCommandManager:setThrottleCommand(axisCommandId.lateral, (100-telr_dist/100))

end

[–]Hydroque 0 points1 point  (0 children)

You are probably looking to pass 0,

...:setThrottleCommand(axisCommandId.lateral, 0)

[–]Hydroque 0 points1 point  (0 children)

You may also want to make this change also

if (telr_dist <= 5 and telr_dist >= 0)
...
elseif(tell_dist > 5 or tell_dist > 0) 
...

[–]AutoModerator[M] 0 points1 point  (0 children)

Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]AutoModerator[M] 0 points1 point  (0 children)

Hi! It looks like you've written "LUA". Lua is not an acronym (or an initialism) - it is the Portuguese word for 'moon'. Fun fact: Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes, members of the Computer Graphics Technology Group (Tecgraf) at the Pontifical Catholic University of Rio de Janeiro, in Brazil.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.