Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Flammable

[Resolved] ACS Scripting Help (while (ThingCountName)

Recommended Posts

Allright there is a problem

http://cs416421.vk.me/v416421150/8e21/d2tJb3wXlxc.jpg

http://cs416421.vk.me/v416421150/8e2a/7NL3YTpJ9uU.jpg



So afterall i dont know how to make it correct.
Here the script i have wrote:

script 1 (void)
{
while (ThingCountName("Demon", 0)); //Count How Much demons, if 0 it will do the action(Floor lower)
ACS_execute(2, 0, 0 , 0, 0); //this will make script repeat execution
{
Floor_LowerTolowest(1, 20); //The action that will happen if demons = 0
}
}

script 2 (void)
{
delay(100);
ACS_execute(1, 0, 0 , 0, 0); //repeating script 1
}


It works, But if there is more than 0 demons it will spam console with "runaway script 1 terminated"
And also it will lagg everytime, if it tries to execute script (because it is counting how much things on map)


So i need help with it, i dont know how to make script correct. How to make couple of enemies and let script execute only when each one of them will die. Any solutions?

P.S.
I am making maps only in UDMF format

Share this post


Link to post

Never tried making this type of script myself, so I can't tell if you're doing anything wrong. But if memory serves, putting a "delay(1)" in the first script should help with the runaway script problem. Not sure where you'd put it, though... maybe it doesn't apply to that type of script...

Share this post


Link to post
schwerpunk said:

Never tried making this type of script myself, so I can't tell if you're doing anything wrong. But if memory serves, putting a "delay(1)" in the first script should help with the runaway script problem. Not sure where you'd put it, though... maybe it doesn't apply to that type of script...

\

As i said console spam messages "runaway script 1 terminated"
And the game laggs everytime, when script count how much demons on the map, so it is not a good idea to make script check how many demons like every 5 secons, because it will be too much lagging. There should be some way that it checks right when Each of demons die. Yes i could put Script execute on all of them, then game will lagg every time i kill 1 demon. This is not good too.

Share this post


Link to post

Did you look at the ZDoom Wiki for ThingCount? Your script is pretty convoluted and there's a good example on the wiki.

// lowers the floor of sector tagged 15, when all barons with tag 10 are dead.
script 1 OPEN
{
    While(ThingCount(T_BARON, 10) > 0)
        Delay(35);
	
    Floor_LowerToLowest(15, 20);
}
For what you want in your example, change T_BARON to T_DEMON, the sector tag of Floor_LowerToLowest, and give your Demons a tag and match it with the first number in ThingCount (unless you have a good reason to not have them tagged in which case change the number to 0.)

In that example, Delay(35) keeps getting executed as long as there are more than 0 Barons of tag 10. Once there are 0 Barons, it goes on to the next part of the script.


Because I have a few minutes, here's a bit of an overview as to how those functions are supposed to work.
ThingCountName("Thing", tag number)
ThingCountName, as you can see from the wiki, is a function that returns an integer, as you might expect since it's counting something. The number is the tag of the things to count, not the number to look for. In this case it's giving you the number of demons still alive with no tag.

Here's a proper while loop:
while (some_test)
{
    statements_to_execute;
}
If some_test is TRUE, which is a number other than 0, the statements in the { } block get executed repeatedly. Once some_test becomes FALSE, which is interpreted as the number 0, the block is skipped and the next part of the script continues. If you only have one statement to execute in the loop, you can omit the { } brackets, like in the example with the Barons above.
There is no semicolon on the line with the while loop. The same goes for all tests like if, for, etc. If you put a semi-colon after the test, then you have an empty loop, and is the same as this
while (test)
{
}
So, you're using the number of Demons alive as a test case in your while loop - this actually works, because as long as there are more than 0, the loop condition is TRUE. Then the loop has you doing nothing, forever -- or until the script gets terminated, which is what that runaway script message is. A loop that repeats forever and has no break with delay hogs up all the processing power it can, which is why you're lagging. Then you've got a bunch of needless back-and-forth running of scripts between 1 and 2. Then somehow the floor lowering part executes, because you probably have something else running script 1 a lot.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×