Scripts / while do loop

Author
Message
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 19th May 2017 23:41 Edited at: 20th May 2017 00:08
First, I am having trouble wrapping my head around the fact that the main function of an entity loops continuously. I have always realized that location, location, location is all important in programming and this combination drives me bonkers.

However, this is not my question because it is something I will need to learn only by experience and only if my brain will then allow me to remember what I have learned.

I have the following code:



I also used this as a condition for the while statement:

while ( GetGlobalSoundPlaying ( 1 ) == 1 )

I assumed that while the audio is playing the condition is true because it returns '1' and it will continue to iterate. When the audio is finished I would think that it would go to "--some more statements." Not so. This is an endless loop. The command GetGlobalSoundPlaying does work. I have tested it and it also works in the lua script Lee had provided. When audio is playing it does return '1' and when NOT playing returns '0'.

Any ideas?
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th May 2017 08:32
The while loop is inside an if that is checking the same thing, so when GetGlobalSoundPlaying returns 1 it will not even reach the while loop.

The 'main' function is called once per frame so there is no need for a while loop, just check whether the sound is playing or not wherever you are calling the play_audio_vocal function (in fact make the function return back a true/false indication as o whether it started the sound or not and use that to change state ).

Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 20th May 2017 11:13
I assume the intent is to force the game to "pause" while the sound is playing?

If so then your theory is fine but I think the problem is that without being allowed to update the global sounds status the command can never know it is no longer true as the core/stock functions are updated once per cycle just like every other script but I may be wrong.
You should add a way to update the sound status yourself.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 21st May 2017 03:14
Thanks AmenMoses and smallg. I appreciate your responding. I'm afraid--because of my dementia and lack of memory retention for new things--I will have to give up on what would not have been difficult for me two years ago. You were right, smallg, regarding the fact I was trying to pause the game. This was my last attempt for creating a audio conversation between an NPC and the player. There would have been several exchanges between them. The problem was trying get one audio to complete before the next one began. I spent over a week trying various techniques to achieve this. Again, the last technique was to pause the game before the letting the loop continue which would play the next audio.

I think I will not use audio at this point and go back to text generated conversations. It's times like this I just feel like going back to classic FPSC for my last game. However, the point of doing this is keeping my brain functioning because I doubt that I will ever finish this one.
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st May 2017 09:02 Edited at: 21st May 2017 09:06
If you know how long the audio is can't you simply wait that amount of time before starting the next one?

i.e.
local timeToWait = math.huge

-- when trigger audio
timeToWait = g_Time + 10 * 1000 -- 10 second wait

-- in code for second audio
if g_Time > timeToWait then
timeToWait = math.huge
-- trigger second audio
end

Just have one time value for each audio portion and have each one set the time value for the next one, or am I missing something?

Edited to add:
If you need to stop the player moving around whilst the audio is playing simply store the player position (and possibly rotation) move the player back to that position every frame until the time expires. (FreezePlayer should do this but I've found it rather buggy to say the least!)
Been there, done that, got all the T-Shirts!
PM
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 22nd May 2017 04:48
I have to ask, "What does math.huge exactly mean?" I googled it in relationship to lua but I couldn't understand the explanations given. Is it a number type such as double precision? I have found out that lua only supports seconds for the timer. Lee would need to create more resolution using 'C' which he uses for the game engine. I did notice the command 'Timer' as in 'x=Timer()' to get the time in milliseconds since the system started. I believe this is used for 'g_time'? I'm still not sure how this all works together.

I've tried various ways (mainly positioning of commands within the 'main' function to no avail. My cloudy/fuzzy brain just can't comprehend I'm afraid. For your info, this is one of the many scripts I tried.



When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 22nd May 2017 09:12 Edited at: 22nd May 2017 18:40
Lua only has one numerical type, double float (i.e. 64 bits), math.huge is simply a built in constant for the maximum possible value.

Try this, I haven't tested it as I am typing this on my Mac.

Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd May 2017 11:37
if amen's script doesn't work then i will also point out i have a script which does the same thing here, perhaps between the 2 you can get something that fits your needs
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 22nd May 2017 20:15
@AmenMoses: Thanks. It works.

@smallg: You have wonderful scripts. I will be using parts of both the 'conversation' and 'waypoint conversation' scripts. I did download a load of scripts from your scripts library. I will now need to go through them and check out how this lua works.
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman

Login to post a reply

Server time is: 2024-12-23 05:26:17
Your offset time is: 2024-12-23 05:26:17