From 6c6a42fbbc231bad6a7921c37cdcb82d17dc225f Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 12 Sep 2024 13:46:30 -0400
Subject: Let test_animation.lua cope with the case of 0 animations.

---
 indra/newview/scripts/lua/test_animation.lua | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/scripts/lua/test_animation.lua b/indra/newview/scripts/lua/test_animation.lua
index c16fef4918..37e7254a6c 100644
--- a/indra/newview/scripts/lua/test_animation.lua
+++ b/indra/newview/scripts/lua/test_animation.lua
@@ -11,18 +11,22 @@ for key in pairs(anims) do
     table.insert(anim_ids, key)
 end
 
--- Start playing a random animation
-math.randomseed(os.time())
-local random_id = anim_ids[math.random(#anim_ids)]
-local anim_info = LLAgent.getAnimationInfo(random_id)
+if #anim_ids == 0 then
+    print("No animations found")
+else
+    -- Start playing a random animation
+    math.randomseed(os.time())
+    local random_id = anim_ids[math.random(#anim_ids)]
+    local anim_info = LLAgent.getAnimationInfo(random_id)
 
-print("Starting animation locally: " .. anims[random_id].name)
-print("Loop: " .. anim_info.is_loop .. " Joints: " .. anim_info.num_joints .. " Duration " .. tonumber(string.format("%.2f", anim_info.duration)))
-LLAgent.playAnimation{item_id=random_id}
+    print("Starting animation locally: " .. anims[random_id].name)
+    print("Loop: " .. anim_info.is_loop .. " Joints: " .. anim_info.num_joints .. " Duration " .. tonumber(string.format("%.2f", anim_info.duration)))
+    LLAgent.playAnimation{item_id=random_id}
 
--- Stop animation after 3 sec if it's looped or longer than 3 sec
-if anim_info.is_loop == 1 or anim_info.duration > 3 then
-    LL.sleep(3)
-    print("Stop animation.")
-    LLAgent.stopAnimation(random_id)
+    -- Stop animation after 3 sec if it's looped or longer than 3 sec
+    if anim_info.is_loop == 1 or anim_info.duration > 3 then
+        LL.sleep(3)
+        print("Stop animation.")
+        LLAgent.stopAnimation(random_id)
+    end
 end
-- 
cgit v1.2.3