#How can I made a sequence of boolean

12 messages · Page 1 of 1 (latest)

stuck gull
#

I have basicly to boolean, A and B.
I want to make A true for a time. And after this time passed make B go true for another time.

I have tried this :
private void setStatusTrueForDuration(String name, long durationInMilliseconds) { if (name.equals("A")) { A= true; ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.schedule(() -> A = false, durationInMilliseconds, TimeUnit.MILLISECONDS); } else if (name.equals("B")) { B = true; ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.schedule(() -> B = false, durationInMilliseconds, TimeUnit.MILLISECONDS); } }

Can someone help me to do that ?

hoary pulsarBOT
#

This post has been reserved for your question.

Hey @stuck gull! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

untold frigate
#

you can't do that with lambdas

#

lambdas require final or effectively final variables, which A and B are definitely not

#

why do you even need to do this? can't you just have A and B be timestamps and compare them with the current time?

stuck gull
#

First thanks for answering, I really appreciate it .
I'm coding a simulator with javaFX. It's basically a following line robot. I have no problem with the code for the comportment but i want to show a real time animation of it's movement. This is where the problems starts.
I can't find a solution to have a methodes of my robot to make it go foward and turned executing only when the previous one stoped.

untold frigate
#

yeah this isn't really it

stuck gull
#

I tried to make this as clear as possible but if it's not for you i be pleased to answer any questions

untold frigate
#

i don't think this is a great or future-proof method

stuck gull
#

Yeah think i get the points, i was trying that because i couldn't find a way to do that with javaFX functions but i might have to ask for help in this field so.

Overall thanks a lot for helping