bugfixes
This commit is contained in:
@@ -1179,31 +1179,38 @@ int LuaAPI::Camera_LookAt(lua_State* L) {
|
||||
// ============================================================================
|
||||
|
||||
int LuaAPI::Audio_Play(lua_State* L) {
|
||||
printf("[Audio_Play] ENTER top=%d\n", lua_gettop(L));
|
||||
psyqo::Lua lua(L);
|
||||
|
||||
|
||||
int soundId = -1;
|
||||
|
||||
|
||||
// Accept number (index) or string (name lookup) like Entity.Find
|
||||
// Check isNumber FIRST — in Lua, numbers pass isString too.
|
||||
if (lua.isNumber(1)) {
|
||||
soundId = static_cast<int>(lua.toNumber(1));
|
||||
printf("[Audio_Play] by index: %d\n", soundId);
|
||||
} else if (lua.isString(1)) {
|
||||
const char* name = lua.toString(1);
|
||||
printf("[Audio_Play] by name: '%s'\n", name ? name : "(null)");
|
||||
soundId = s_sceneManager->findAudioClipByName(name);
|
||||
if (soundId < 0) {
|
||||
printf("[Lua] Audio.Play: clip '%s' not found\n", name);
|
||||
printf("[Audio_Play] clip not found\n");
|
||||
lua.pushNumber(-1);
|
||||
return 1;
|
||||
}
|
||||
printf("[Audio_Play] found at index %d\n", soundId);
|
||||
} else {
|
||||
printf("[Audio_Play] invalid arg type\n");
|
||||
lua.pushNumber(-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int volume = static_cast<int>(lua.optNumber(2, 100));
|
||||
int pan = static_cast<int>(lua.optNumber(3, 64));
|
||||
|
||||
|
||||
printf("[Audio_Play] play(%d, vol=%d, pan=%d)\n", soundId, volume, pan);
|
||||
int voice = s_sceneManager->getAudio().play(soundId, volume, pan);
|
||||
printf("[Audio_Play] voice=%d OK\n", voice);
|
||||
lua.pushNumber(voice);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user