I have a while script that, for now, I have running before the fade-in, just so the player knows something's happening. It's something that loads in the room that takes ten seconds to load. My question is: Does everything need to stop while something else is loading?
Pretty much any while script makes everything stop, even the clock I put in the corner. Other games will have stuff loading while you're playing. Is there something I can do?
I don't think any game loads anything while playing.
You can do stuff continuously in the background while the player is playing though.
The function you're looking for is repeatedly_execute in the global script and the room's rep_ex event.
The code inside will be run 40 times a second (with a default GameSpeed setting of 40 FPS that is).
You could also make a function called repeatedly_execute_always in the global or room script. This allows you to have things running even while the game is blocked (like your clock, for example).
function repeatedly_execute_always()
{
//Clock animation, other stuff, etc.
}
Quote from: Creator on Mon 20/06/2011 05:02:10
You could also make a function called repeatedly_execute_always in the global or room script. This allows you to have things running even while the game is blocked (like your clock, for example).
Aha! Thank you!
In your first post you said you're running a while loop in the player enters room before fade-in function. You don't seem to understand what that means.
First of all, anything in the before fade-in function is going to be executed before the screen fades in. That means you will not see any objects, any characters, any GUIs, any overlays, or anything at all until the function is finished executing.
Secondly, a while loop does not allow other script functions to execute while it is running. The exception is that if you call Wait inside the loop, then repeatedly_execute_always will be allowed to run, but that's it.
Even running something from repeatedly_execute_always will not override the first point. Until the before fade-in function is completely finished (including any while loops you're running within that function), then you're not going to be able to see anything.
From there I'm really curious what you're doing that is causing your room to take 10 seconds to load. Unless this is the very first room and you've got several hundred characters, the room full of objects, and you've got some massive structs with String or File operations going on in there (all of that combined), I honestly can't fathom why your room would be taking that long to load unless you've done something to directly cause the problem.
Furthermore, you shouldn't use repeatedly_execute_always (or repeatedly_execute) for animations unless you have an explicit need to do so. For most cases using a Character, Object, or GUI Button would be a better fit for your animation needs.
Simply doing things without understanding why you're doing them or what the problem was to begin with is not a good idea, especially when it comes to programming. Just because something might give the appearance of the results you want does not mean that you're doing it right.
QuoteIn your first post you said you're running a while loop in the player enters room before fade-in function. You don't seem to understand what that means.
First of all, anything in the before fade-in function is going to be executed before the screen fades in. That means you will not see any objects, any characters, any GUIs, any overlays, or anything at all until the function is finished executing.
I do know, I just preferred seeing nothing to seeing a blank room where the player can't click anything and doesn't know why.
QuoteSecondly, a while loop does not allow other script functions to execute while it is running. The exception is that if you call Wait inside the loop, then repeatedly_execute_always will be allowed to run, but that's it.
Even running something from repeatedly_execute_always will not override the first point. Until the before fade-in function is completely finished (including any while loops you're running within that function), then you're not going to be able to see anything.
I liked this approach better than doing it before or after the fade-in because it lets the clock run AND I can say "Loading" or something while it's loading IF I include a Wait(1); inside of a While loop. Display blocks scripts but a picture of the word Loading can stay on while the script is running. Although a long fade out + fade in has its charms.
QuoteFrom there I'm really curious what you're doing that is causing your room to take 10 seconds to load...
Yea, that's me.
QuoteFurthermore, you shouldn't use repeatedly_execute_always (or repeatedly_execute) for animations unless you have an explicit need to do so. For most cases using a Character, Object, or GUI Button would be a better fit for your animation needs.
Simply doing things without understanding why you're doing them or what the problem was to begin with is not a good idea, especially when it comes to programming. Just because something might give the appearance of the results you want does not mean that you're doing it right.
Speaking of that. If, say, you opened Task Manager while running your program and saw the amount of memory and cpu usage increased when you run a script, is there a way to lower that back once the script is done?
You mean releasing the memory allocated by a program when it's finished with it? Yeah, that's normal behavior for any properly written program. If the program isn't releasing the memory then you have a memory leak, and I've never heard (in over seven years of using the program) of a single case of AGS leaking memory.
So this load time of 10 seconds is just "you" as you say? From that, and seeing as you refused to give any actual indication what you're doing, I can only then assume that you're forcing a 10 second "load" time while not actually loading anything at all.
And if the screen is faded out then what are you using to display this "Loading" message? You specifically said you're not using Display, but that's the only thing I'm really aware of that isn't drawn behind the fade. GUIs, Overlays, Characters, and Objects are all drawn behind that, so how are you showing said "picture"? You're giving some very contradictory and misleading feedback here, so I honestly don't have a clue what you're actually doing (again because you refuse to actually give any indication of what you are doing in favor of just randomly tossing these disconnected thoughts around).
In short, you sir, make as much sense as a drunken momerath.
You're making the player wait needlessly because it has its charms? Thanks for the warning not to play any of your games.
A drunken momerath, outgrabe?
My script takes ten seconds. These were my choices:
A. Let the player see the room and not be able to do anything (after fade-in)
B. See nothing and have a drawn-out fade in (before fade-in).
C. If I combined after fade-in with a repeatedly_always clock and a wait within a while along with a 'loading' picture, this would show that the game was still running.
I wasn't refusing you, it's just my script wasn't the problem. This thread was about being able to have stuff running simultaneously.
I was certain nothing was wrong with my script and I've found that if I take the following out, there's no memory leak:
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(35);
sprite.Crop(0, intA, sprite.Width, intB);
surface.DrawImage(0, intC, sprite.Graphic);
sprite.Delete();
surface.Release();
This is rearranged from how it's typically shown in the help file - I've tried releasing the surface before deleting the sprite. I'm not sure what's wrong.
I want to be clear, so please bear with me. I'm not trying to be rude, but I'm quite honestly debating whether or not I should even continue trying to help you, because you're not responding to half of what I'm saying.
Specifically what I'm referring to is that you still have not given any indication whatsoever what makes you think that you're going to be able to see this before the room is faded in. You're drawing it on the room background. So unless you've just been saying, consistently, the wrong thing and saying that you're doing it before the room is faded in all the while meaning after the room is faded in, then I absolutely guarantee you that you aren't going to see that, and furthermore if you say that you can, then you're either delusional, or a liar.
Also, I fear that coining the term "memory leak" here may have given you some horrible free license to blame your problems on any and everything else. AGS will release the memory when it's finished with it. That is not a memory leak.
You said that your "script wasn't the problem" because "this thread was about being able to have stuff running simultaneously" yet the reason you weren't "able to have stuff running simultaneously" is because you were using while loops, and just expecting the game to continue going on in the background as if your script wasn't running. That sounds pretty well like a scripting issue to me.
The code you posted isn't remotely sufficient to cause your room to take 10 seconds to load, so until you can provide something that actually shows what you're doing that is causing it to take this long, we are going to continue in our belief that you're just intentionally delaying the load time for no reason other than personal beliefs about game aesthetics.
As for the code you posted, there's not actually anything wrong with the way you have it written. The memory might not be released back to the OS immediately, but again that doesn't indicate a memory leak.
However, the fact that you said that the described "issues" with the memory aren't present if you take that code out, then that leads me even further to believe that you're not really doing much of anything in the way of loading any data...
Well, why not move your code into room after fadein? Display your loading picture in room before fade in, then run your 10 second code in room after fade in and then remove your loading picture. This way when your code has finished loading your 10 seconds worth of whatever it is, you can go straight from your loading picture to the room.
On the off chance that your code doesn't take 10 seconds to load but you want to give the impression that it does, then why not send the player to another room first with your loading picture as the background and Wait (400);?
I've tried it a few times and found that while running the script once increases the memory and cpu usage, running it a few times increases it temporarily but then lowers it back to the elevated level, so it does not keep taking more and more memory.
I've found the documentation about script blocking, something I didn't know about but now I see how it works. This thread was only ever about having two scripts running at once, or one script running while still being able to move, but now I see that while loops force the game to wait.