What I'm trying to do is:
1) use the Ruby TTS gem to read some text.
2) while the text is being read, I want to loop through an animation.
The way I'm calling the animation is this:
def animation
i = 1
while i < 3
print "\033[2J"
File.foreach("lib/narrabot/flair_folder/#{i}.txt") { |f| puts f }
sleep(0.03)
i += 1
end
end
What seems like a quirk (or feature) of the TTS gem is that if you hit a button on your keyboard while it's running... it will replay from where you interrupted... So, when I tried to run the loop assuming I could just "play" the text, TTS essentially stuttered and didn't run the animation until it ended and then it went back to the beginning.
I just required this gem... https://github.com/grosser/parallel but am not sure how to tackle my goal.
In case you're curious -- my project is here: https://github.com/AdamWeissman/narrabot
What I'm attempting to do is use TTS to read Aesop's Fables... and while a Fable is being read... an ascii animation of a fire will run in the background. Eventually, I hope to replace the image of the fire with an ascii face (sorta like a sock puppet... the intent is to get the mouth to move in sync -- relatively -- with the speech... but that's a long way off).
Related
I have been trying to create a sound every time your mouse leaves and enters this button. The code doesn't really work. I have tried this on a local script and a normal script:
script.Parent.MouseEnter:Connect(function()
local sound = script.Parent.Parent.hit
sound:Play()
end)
script.Parent.MouseEnter:Connect(function()
local soundTwo = script.Parent.Parent.hitS
soundTwo:Play()
end)
```[enter image description here][1]
[1]: https://i.stack.imgur.com/5niz4.png -- The explorer of the game (I used script and local script btw and none of them changed anything, but i do think local script would work better for a gui)
You can try adding the following lines at the top of your code.
if not sound.IsLoaded then sound.Loaded:Wait() end
if not soundTwo.IsLoaded then soundTwo.Loaded:Wait() end
Also, both of your functions are for MouseEnter. Try changing one to MouseLeave.
So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.
I'm trying to write a simple game in Ruby (ver 2.2.6) on Windows. I installed the Gosu gem to handle the audio, and I have a soundtrack file that I would like to play:
#soundtrack = Gosu::Song.new("theme.ogg")
I cannot use Sample, because I need to be able to pause.
def play_soundtrack
#soundtrack.play(looping = true)
end
def pause_soundtrack
print "Paused "
#soundtrack.pause
end
Running this only plays the first note of the theme, and then no sound will play. Gosu::Sample still works as it should, so I'm not sure what could be wrong with my use of Gosu::Song.
This is not possible with Gosu right now, Song#play does not work without a window. Because Gosu does not use a background thread to play audio, there is an internal Song::update() method that needs to be called periodically to keep the song playing. Gosu::Window#show does this once per tick. There is no way to directly call this method from Ruby. The only workaround is to show a tiny window while audio is playing.
I've opened a GitHub issue because this should either be documented or fixed.
I have been working on a makeshift RPG, and the Regenerate function, is supposed to be called every 3 seconds, NO MATTER WHAT THE PLAYER's STATUS IS
For Example:
Shoes.app do
# Display on main screen
animate do
# Set para(s) to current values of health and other stats
end
every 3 do
RegenerateVitals
end
end
But at times, the user will click on buttons that will trigger functions and new windows (the base window will keep opened in the background at all times.)
Do the every function really runs behind the scenes every 3 seconds no matter what menu the player is on? Or do I need to do something else for that?
Thanks.
Yes, the specification is that every calls the block no matter what (as long as the main windows stays open). I looked up the implementation of shoes4 and that one definitely does it (using the SWT scheduler) but other implementations such as Shoes 3.1, 3.2 and green shoes should do the same.
I need to run a ruby client that wakes up every 10 minutes, takes a screen-shot (ss) of a users screen, crops part of the (ss) out and use's OCR to check for a matching word....its basically a program to make sure remote employees are actually working by checking that they have a specific application open & the case numbers shown change.
Not sure where to even start when it comes to taking a screen-shot and cropping it, has anyone done any kind of screen capture work using Ruby?
The app will run on OSX using Ruby 1.9
Thanks!
On OS X you can use the screencapture command in the terminal to capture the screen, so capturing the screen from Ruby shouldn't be more than
def screen_capture(path)
`screencapture #{path}`
end