Can someone help me fix my broken looped idle animation code? - animation

So, in Roblox Studio, I tried making an R15 rig play an idle animation, ID:12297693014. However, the script won't work. It's a local script placed under a "Humanoid".
I tried:
local animationId = 12297693014
local character = script.Parent
local function playAnimation()
character.Humanoid:PlayAnimation(animationId)
end
while true do
playAnimation()
wait(1)
end
but the rig just stayed as a T-Pose, which is what I saw before I played the game.
What's wrong with the code? And most importantly, how do I fix this?

Well buddy, looks like you're stuck in a loop that's going nowhere fast. The issue with your code is that you're telling the rig to play the animation in a loop, but you're not actually providing a stop point. So, the animation will keep playing indefinitely, leading to your T-Pose predicament.
Here's a fix:
local animationId = 12297693014
local character = script.Parent
local function playAnimation()
character.Humanoid:LoadAnimation(animationId):Play()
end
playAnimation()
This should work as a charm, but if it still doesn't, try giving your rig a break and giving it some time to rest between animations. Remember, even digital beings need a break!

Related

Hammerspoon Key Repeats

I am so glad I found hammerspoon. I am having issues coming from windows to mac os. I have been using autohotkey in the past and have this script that I cannot live without while playing world of warcraft. I suffered a hand injury and can't play without the following script:
{
$r::
Loop
{
if not GetKeyState("r", "P")
break
Send r
Sleep 40
}
return
}
All it does is key repeat the letter r while holding it down. I use an addon in world of warcraft called gnomesequenceenhanced to put my abilities in to play. and the scritp uses the same button over and over until released to cast my abilities.
I would be forever greatful if you would be able to get this so I can upload and use this in the config and save the init.lua

What event fires when a player stands on a block in Roblox?

I want to change the colour of a part when a player stands on it but instead of putting the script inside the part can i put the script in the workspace and identify the part from an event, like Humanoid touched or something?
The reason is that i have 100's of parts which need to react to a touch event so i don't want to put the same script in each part.
Pseudo-code might be
Player touch part event fired
Identify part from event and change colour of part
Thanks
As M. Ziegenhorn wrote, you could put the script in the character or in the foot directly. That would be the "easiest" way of achieveing this.
However, you could also connect a function to each part easily.
In the code below, we check through a model in workspace named 'TouchParts' which (assumingly) contains the parts you want to tie the touch-function up to.
function Touched(self, Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChildOfClass'Humanoid' then
-- We know it's a character (or NPC) since it contains a Humanoid
-- Do your stuff here
print(Hit.Parent.Name, 'hit the brick', self:GetFullName())
self.BrickColor = BrickColor.new('Bright red')
end
end
for _, object in pairs(workspace.TouchParts:GetChildren()) do
if object:IsA'BasePart' then
object.Touched:connect(function(Hit)
Touched(object, Hit)
end)
end
end
Doing it this way means anything in your character touching the part(s) will fire the Touched-event, so you would have to add in a check to see whether if tie part touching is a leg or not.
The pros of binding the function to each part instead of to the leg is that the function is only called when you actually touch one of the intended parts, instead of ANYTHING you touch. However, with an increased amount of parts you connect it to, there's also an increased amount of events which will be triggered and is stored in memory. Probably not noticeable on the scale you're working with, but worth keeping in mind.
Been a while since I coded something on roblox so please excuse any blunders I make.
local parent = workspace.Model --This is the model that contains all of that parts you are checking.
local deb = 5 --Simple debounce variable, it's the minimum wait time in between event fires, in seconds.
local col = BrickColor.new("White") --The color you want to change them to once touched.
for _,object in next,parent:GetChildren() do --Set up an event for each object
if object:IsA("BasePart") then --Make sure it's some sort of part
spawn(function() --Create a new thread for the event so that it can run separately and not yield our code
while true do --Create infinite loop so event can fire multiple times
local hit = object.Touched:wait() --Waits for the object to be touched and assigns what touched it to the variable hit
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Either finds the player, or nil
if player then --If it was indeed a player that touched it
object.BrickColor = BrickColor.new(col) --Change color; note this is also where any other code that should run on touch should go.
end
wait(deb) --Wait for debounce
end
end)
end
end
This is probably one of the most, if not the most efficient way of doing this.
When a player stands on a block, the value "FloorMaterial" (which is in Humanoid) will be telling you what material the user is standing on, but if the user isn't standing on anything, this value will be nil.
Another efficient method is to use Rays. You would need to create a ray from your HumanoidRootPart.
Example:
IsOnGround=function()
local b=false;
local range=6;
local char=game:service("Players").LocalPlayer.Character;
local root=char:WaitForChild("HumanoidRootPart",1);
if root then
local ray=Ray.new(root.CFrame.p,((root.CFrame*CFrame.new(0,-range,0)).p).unit*range);
local ignore={char};
local hit,pos=workspace:FindPartOnRayWithIgnoreList(ray,ignore,false,false);
pcall(function()
if hit then
b=true;
end
end)
else
print("root not found");
end
return b;
end
This would cast a ray from the HumanoidRootPart, towards the direction where the ground should be, with a distance of 6 studs.
Sadly, this method isn't very effective with R15 characters as far as I know.

Debugging Step Into, Over, Out within VB6 IDE closes the class window

I am experiencing very strange behavior within VB6 IDE whenever the break point hits(Step Into, Out, Over), the class is closed and makes it impossible to debug. Then within window-Cascade i can re-open the class but again when break point hits, the class is closed. Can anyone help please.
Step execution does sometimes behave that way. The reason is that VB is event driven and when an event occurs, then the code behind that event will run, and your code that you are stepping through might NOT be the code that gets run, so things change and code runs while your PAUSED code is still on hold.
When I encounter that I overcome it by using debug.print to send my monitored variables' current values to the OUTPUT window, or if you need more elaborate capability, write a sub that sends the data to a local text file and then invoke that sub as needed, passing into the variables ( and labels ) that you want displayed.
Once debug.print or a logging routine is in place then run the code WITHOUT pauses or breaks. The debugging output will tell you what is happening, in what order etc, so no need to stop the code or risk altering the order of execution.
Be sure to include lots of 'context' data such as : 'Entering SUB_XYZ, Param values are A, B, C... NOW at line 99 in SUB XYZ.... NOW in TRUE side of IF TEST # 1....
Include time stamps on all outputs.
Put your tracing logic only around the suspected problem area, expand from there only as needed.
It's a pain, but it works.
I finally resolved this issue and problem was within Display settings within windows 10. Basically if I apply vertical settings by placing both screen vertically 2nd on top of first then this issue happens,if i apply horizontal settings then this issue does not happen.
problematic settings with vb
settings that does solves debugging issue. VB is so weird and old cannot cope with display settings

How to detect that sound has ended in the XNA MediaPlayer?

I know how to use MediaPlayer.Play(song); to start playing some song/effect.
But how to detect that song/effect ended playing?
You may want to try implementing these two events:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.activesongchanged.aspx
and
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.mediastatechanged.aspx
An alternate way would be to keep a MediaState variable called "previousState" or whatever, and each Update(), check the previous state for Stopped or Paused, and run whatever code you want in that if. Of course, afterward, update the previous by doing:
previousState = MediaPlayer.State;

wxruby and rubymsn

I'm currently playing with wxRuby and RubyMSN to learn to program desktop-programs. I know it is a hard task instead of just crating a notepad etc, but I need a bigger task than a notepad.
I now do manage to use them by them self, but I cant get them to work together. The problem is the loop.
RubyMSN wants to have an endless loop like
while true
sleep 1
end
or using the GUI's mainloop or something
I currently have this code as the loop
TheApp.new.main_loop()
while true
sleep 1
end
I have my window working, and the main_loop doing something. But I cant log in, it's like I doesn't have any loop (from the tutorial), I only get one debug line. But as soon as I close the window and lets the endless loop do it's job it works like a charm.
Someone ?
Worked for me. Try this: copy the minimal sample from the wxruby distribution, and modify minimal.rb so that you start your msn thread just before the wx main loop:
require 'msn/msn'
conn = MSNConnection.new("rubybot#channelwood.org", "secretpassword123")
conn.start
# Wx::App is the container class for any wxruby app. To start an
# application, either define a subclass of Wx::App, create an instance,
# and call its main_loop method, OR, simply call the Wx::App.run class
# method, as shown here.
Wx::App.run do
self.app_name = 'Minimal'
frame = MinimalFrame.new("Minimal wxRuby App")
frame.show
end
You'll need to symlink the msn directory inside the minimal directory to get the require statement working, of course.
You don't need the while true {sleep 1} loop; that's just to prevent the program from exiting so that your msn thread can keep running. The wx main loop accomplishes the same purpose.

Resources