Jump to content




Proof of concept help, with parallel API.


  • You cannot reply to this topic
13 replies to this topic

#1 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 August 2012 - 12:10 AM

I have been trying to complete a proof of concept, whereas a user could have an animated menu, while it is waiting for an input from the user. So far, I have it waiting for an input just fine, but I have been having problems with it trying to execute other code, since for an animation to work, I need for the first animation to loop. My goal with the proof of concept is to have a character, in this case Kirby, enter, and then wait in the middle of the screen for the user input. I have only one command to give Kirby at this time, and that is to DANCE! Problem is, when I give him the dance command, the idle command is still running due to the parallel API. Here is the code I have so far, and much of it has been generously worked on by the other members of the Ask a Pro section:
-- screen functions
function border()
local w, h = term.getSize()
local s = "+"..string.rep("-", w - 2).."+"
term.setCursorPos(1, 1)
term.write(s)
for y = 2, h - 1 do
  term.setCursorPos(1, y)
  term.write("|")
  term.setCursorPos(w, y)
  term.write("|")
end
term.setCursorPos(1, h)
term.write(s)
end
function kirbyEnter()
local mY = mY/2
term.setCursorPos(2,mY)
write(">")
term.setCursorPos(2,mY)
sleep(.2)
write("')>")
term.setCursorPos(2,mY)
sleep(.2)
write(".')>")
term.setCursorPos(2,mY)
sleep(.2)
write("('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("<('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("  ( V') ")
term.setCursorPos(2,mY)
sleep(.2)
write("  <(   )>")
term.setCursorPos(2,mY)
sleep(.2)
write("    ('V )")
term.setCursorPos(2,mY)
sleep(.2)
write("    <('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("	  ( V')")
term.setCursorPos(2,mY)
sleep(.2)
write("	   <(   )>")
term.setCursorPos(2,mY)
sleep(.2)
write("		 ('V )")
term.setCursorPos(2,mY)
sleep(.2)
write("		 <('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("		   ( V')")
term.setCursorPos(2,mY)
sleep(.2)
write("		   <(   )>")
term.setCursorPos(2,mY)
sleep(.2)
write("			 ('V )")
term.setCursorPos(2,mY)
sleep(.2)
write("			 <('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("			   ( V')")
term.setCursorPos(2,mY)
sleep(.2)
write("			   <(   )>")
term.setCursorPos(2,mY)
sleep(.2)
write("				 ('V )")
term.setCursorPos(2,mY)
sleep(.2)
write("				 <('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("				  <('.')>")
term.setCursorPos(2,mY)
sleep(.2)
write("				   <('.')>")
end
function kirbyDance(mX,mY)
local mX = mX/2
local mY = mY/2
term.setCursorPos(mX - 4,mY)
write("^('.')>")
sleep(.5)
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.')^")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("^('.')>")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.')^")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("^('.')>")
term.setCursorPos(mX - 4 ,mY)
sleep(.5)
write("<('.')^")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write(" (>'.')>")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.'<) ")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write(" (>'.')>")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.'<) ")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write(" (>'.')>")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.'<) ")
term.setCursorPos(mX - 4,mY)
sleep(.5)
write("<('.')> ")
sleep(.5)
term.setCursorPos(mX - 4,mY)
end
function select()
term.setCursorPos(2,10)
write("Make your selection")
term.setCursorPos(2,12)
write("Dance")
term.setCursorPos(2,17)
write("Selection: ")
--other options available in the future
  local input = read()
  if input == "dance" then
    kirbyDance(mX, mY)
  else
    print("INVALID")
    term.clear()
    border()
    select()
  end
end
function kirbyIdle()
local mX = mX/2
local mY = mY/2
while true do
term.setCursorPos(mX - 4,mY)
write("<('.')>")
sleep(5)
term.setCursorPos(mX - 4,mY)
write("<(-.-)>")
sleep(.5)
end
end

-- end screen functions
mX, mY = term.getSize()
term.clear()
border()
kirbyEnter()
parallel.waitForAny(kirbyIdle,select)
So far, I only want this to run once. Waiting for the input, and then just stopping.

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 August 2012 - 12:36 AM

Well, I guess you could break the menu/selection loop, so the parallel call will return, then you use the selection from the menu to run the corresponding function. Put that in a loop and it should work. But there's an easier way: don't use parallel. Use another menu that doesn't call read, so you can simply use events. I'll work on it and post what I get.

#3 BigSHinyToys

  • Members
  • 1,001 posts

Posted 04 August 2012 - 12:56 AM

I have made some modifications to your code fixed part of the animation and set up some control functions Please try this.
Spoiler


#4 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 August 2012 - 01:11 AM

View PostBigSHinyToys, on 04 August 2012 - 12:56 AM, said:

I have made some modifications to your code fixed part of the animation and set up some control functions Please try this.
Spoiler
Ok, you totally fixed it!!! Now I just have to have Kirby dance a little better!

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 August 2012 - 01:17 AM

Ok, a little late but here's what I have:
Spoiler
It uses another menu, so it doesn't need parallel, and the animations are easier to change. I tested it and works fine, although I'm not sure if the enter animation should look like that :P/>

#6 BigSHinyToys

  • Members
  • 1,001 posts

Posted 04 August 2012 - 01:25 AM

View PostMysticT, on 04 August 2012 - 01:17 AM, said:

Ok, a little late but here's what I have:
-- snip --
It uses another menu, so it doesn't need parallel, and the animations are easier to change. I tested it and works fine, although I'm not sure if the enter animation should look like that :P/>
I always find it interesting our differing philosophies I try to work with the provided code as much as possible and you make the best possible solution to the problem demonstrated very well in our codes above.

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 August 2012 - 01:30 AM

MysticT, I only have one question about your code:
What is the _,s in the drawAnimation() function, and what does it do? I have never seen that before.

#8 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 August 2012 - 01:32 AM

View Postcraniumkid22, on 04 August 2012 - 01:30 AM, said:

MysticT, I only have one question about your code:
What is the _,s in the drawAnimation() function, and what does it do? I have never seen that before.
It's just some variables used in the for loop. The _ is used normally to name variables that you don't use.

#9 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 August 2012 - 01:40 AM

Ok, that's neat. BTW, the code you have is great, but it did not keep looping the idle after giving the initial command. Any way around this?

#10 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 August 2012 - 01:45 AM

Did you try it? The idle animation works fine for me, even after doing the dance.

#11 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 August 2012 - 01:49 AM

Yeah, when I hit enter to select dance, he just stays there after dancing. No more blinking eyes...

Edit: I am using a CC emulator...if that means anything. I'm using this one.

#12 BigSHinyToys

  • Members
  • 1,001 posts

Posted 04 August 2012 - 01:52 AM

View PostMysticT, on 04 August 2012 - 01:45 AM, said:

Did you try it? The idle animation works fine for me, even after doing the dance.
I tested it and I have same problem animation doesn't play because timer event occurs during animation meaning it ends the timer loop

#13 BigSHinyToys

  • Members
  • 1,001 posts

Posted 04 August 2012 - 01:55 AM

fixed MysticT's code
Spoiler


#14 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 August 2012 - 01:55 AM

Hmm, you'r right, I forgot to reset the timer. This should work:
Spoiler


View PostBigSHinyToys, on 04 August 2012 - 01:55 AM, said:

fixed MysticT's code
-- snip --
That would work, but it would reset the timer each time you press a key, so the idle animation wouldn't work correctly.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users