Jump to content
  • 0

How do I use the Counter Variable Script more than once ?


PITTSBURGH PENGUINS

Question

This is the Counter Variable Script :

 

int totalenemies = 4;
int killcount;

script "Enemy Death Monitor 1" (void)
{
    killcount++;

    if (killcount >= totalEnemies)
    {
        Floor_LowerByValue (12, 64, 32);
    }
}

 

So every time I "Double Define" this script according to Doom Builder I've "Double Defined" it and it doesn't work . But The While Loop Script can be used multiple 

times , the only problem is is that the While Loop Script doesn't work , But the Counter Variable Script works every time I've used it , I need it to work multiple times because the current map I'm working on needs alot of scripting but it Actually needs to work 

 

If anyone can help thanks...

Edited by PITTSBURGH PENGUINS
messed up the title of topic

Share this post


Link to post

27 answers to this question

Recommended Posts

  • 0

It sounds like it might help if you went through an introduction to ACS scripting so that you understand what’s going on with your script and your variables here - Chubzdoomer is a very prolific tutorial maker! 

 

You’re getting “double defined” because you’re trying to define two scripts with the same name - the second would have to be called something like “Enemy Death Monitor 2” and use its own variables so that it doesn’t clash with the ones you already have - int totalenemies2 and int killcount2, for example.

Share this post


Link to post
  • 0

A better way to do this is by tagging the enemies you need to be killed, and then do a While ThingCount loop inside an OPEN script instead of void. I can write an example if you need one.

Share this post


Link to post
  • 0
5 hours ago, DavidN said:

It sounds like it might help if you went through an introduction to ACS scripting so that you understand what’s going on with your script and your variables here - Chubzdoomer is a very prolific tutorial maker! 

 

You’re getting “double defined” because you’re trying to define two scripts with the same name - the second would have to be called something like “Enemy Death Monitor 2” and use its own variables so that it doesn’t clash with the ones you already have - int totalenemies2 and int killcount2, for example.

Oh Ok that makes sense , Although I have already named my script Death Monitor 2 rather than death monitor since i have 2 scripts , but I thought it always had to be called int Total enemies and kill count but i guess not LOL , well now I'm finishing this map thanks to you dude ... thanks man : )

Share this post


Link to post
  • 0
4 hours ago, Nevander said:

A better way to do this is by tagging the enemies you need to be killed, and then do a While ThingCount loop inside an OPEN script instead of void. I can write an example if you need one.

Yeah for sure please & thanks I'VE never heard of an open script ...

Share this post


Link to post
  • 0

An OPEN script type executes as soon as the map loads instead of a (void) script waiting to be executed. By tagging the enemies that must be killed, and using a while loop to count the tagged things, you can have the script automatically execute when the conditions are met. I can write you an example script, give me a few hours.

Share this post


Link to post
  • 0
2 minutes ago, Nevander said:

An OPEN script type executes as soon as the map loads instead of a (void) script waiting to be executed. By tagging the enemies that must be killed, and using a while loop to count the tagged things, you can have the script automatically execute when the conditions are met. I can write you an example script, give me a few hours.

OK Thanks man : ) I appreciate it , this scripting is tricky I don't understand it most of the time one minute it works the next it's broken again and I'm stuck working on the same map for 2 WEEKS backtracking over and over unable to build the next map , it sucks bad : (

Share this post


Link to post
  • 0

Basically this is what my script looks like :

 

int totalenemies2 = 3;
int killcount2;

script "Enemy Death Monitor 2" (void)
{
    killcount++;

    if (killcount2 >= totalEnemies2)
    {
        Door_Open (24, 16, 0);
    }
}

DavidN up there said this would work , it did for a while but then I tried to add a few more enemies to the script for difficulty changes , I went back to play my map and the door would no longer open , the script would not execute , I got in contact with Chubz Doomer , He actually looked over my script and tried to help me with the problem , He said that adding 2 to the if killcount >= totalEnemies  would work , as you see I did and still nothing , nothing changed the script would still not execute I don't get it still and my map still doesn't work today ... I've gotten nowhere :( 

If anyone see's anything wrong with my script on top of this reply , please let me know thanks...

 

Share this post


Link to post
  • 0

So I've been messing with the script and trying to fix the problem , it's stubborn it will not work no matter what I do , I've tried Kill , Enter , Void , and even open 

none of those executions work , And I don't know if there are any more executions I haven't tried but even if there were IDK if they'll work :( Scripting is a pain 

If I can get this script done then I can move onto Map 11 so like I said anyone seeing this please try your best to help me , thanks 

Share this post


Link to post
  • 0

I'm sorry, but the killcount and killcount2 variables have no value and since they haven't they cannot increment.

I downloaded the map and gave killcount a value of 0 to test it out and the script works perfectly fine.

Share this post


Link to post
  • 0
3 minutes ago, Kan3 said:

I'm sorry, but the killcount and killcount2 variables have no value and since they haven't they cannot increment.

I downloaded the map and gave killcount a value of 0 to test it out and the script works perfectly fine.

Really ? You mean you fixed it ? Thanks man I owe you 1 :)

But can you send me the script layout so I can reference off of that ? thanks 

Edited by PITTSBURGH PENGUINS

Share this post


Link to post
  • 0
2 hours ago, PITTSBURGH PENGUINS said:

Really ? You mean you fixed it ? Thanks man I owe you 1 :)

But can you send me the script layout so I can reference off of that ? thanks 

Well, it does the things that it is supposed to do when I kill all of the required monsters.

There's no layout or anything, you just need to give those 2 variables the value 0, so, instead of just int killcount; go for int killcount = 0; like you did for the other variable.

(unless you want to change layout, but there's no real need)

Share this post


Link to post
  • 0

Just a heads up:  While it doesn't hurt to do what Kan3 is suggesting, it isn't strictly necessary either.  The reason is that all uninitialized integers start at 0.

 

The main issue with the code you posted above is that you're incrementing a variable called killcount, yet your condition is checking against a variable called killcount2.

 

Unless you increment killcount2, its value will always be 0 and the "if" condition will always evaluate to false.

 

My personal recommendation is to take a big step back and learn the absolute basics of scripting before going any further.  Otherwise you're going to keep hitting one roadblock after another and end up nowhere fast.

 

The ZDoom Wiki has a beginner's guide (and is an invaluable reference in general) and I've got an entire video series dedicated to learning ACS from the ground-up.  Slow down, learn, and practice so that you truly understand what you're doing.  This definitely isn't the type of thing you want to rush!

Edited by Chubzdoomer

Share this post


Link to post
  • 0
50 minutes ago, Chubzdoomer said:

Just a heads up:  While it doesn't hurt to do what Kan3 is suggesting, it isn't strictly necessary either.  The reason is that all uninitialized integers start at 0.

 

The main issue with the code you posted above is that you're incrementing a variable called killcount, yet your condition is checking against a variable called killcount2.

 

Unless you increment killcount2, its value will always be 0 and the "if" condition will always evaluate to false.

 

My personal recommendation is to take a big step back and learn the absolute basics of scripting before going any further.  Otherwise you're going to keep hitting one roadblock after another and end up nowhere fast.

 

The ZDoom Wiki has a beginner's guide (and is an invaluable reference in general) and I've got an entire video series dedicated to learning ACS from the ground-up.  Slow down, learn, and practice so that you truly understand what you're doing.  This definitely isn't the type of thing you want to rush!

You Know What Chubz , Your right :) I'm gonna try to slow down & I'm gonna watch your whole video series , That should help big time , then I should understand what I'm doing better thanks ... 

Share this post


Link to post
  • 0
1 hour ago, Kan3 said:

Well, it does the things that it is supposed to do when I kill all of the required monsters.

There's no layout or anything, you just need to give those 2 variables the value 0, so, instead of just int killcount; go for int killcount = 0; like you did for the other variable.

(unless you want to change layout, but there's no real need)

Yeah , I'm gonna try that , it should work if it worked for you it should work for me thanks man :)

After this map My 1'st episode of my game is over & I can finally get to work on episode 2 "Earth"

can't wait!!!

Edited by PITTSBURGH PENGUINS

Share this post


Link to post
  • 0
1 hour ago, Kan3 said:

Well, it does the things that it is supposed to do when I kill all of the required monsters.

There's no layout or anything, you just need to give those 2 variables the value 0, so, instead of just int killcount; go for int killcount = 0; like you did for the other variable.

(unless you want to change layout, but there's no real need)

OK Heads up, I got it working this whole time I though I had to call it killcount & totalenemies but I learned I don't in  

This video , thanks for the video Chubz good thing I watched it :) Now I can get this ol' map finished 

thanks guys for all your help I'll give you feedback if anything else happens or stops working 

Edited by PITTSBURGH PENGUINS

Share this post


Link to post
  • 0
11 minutes ago, PITTSBURGH PENGUINS said:

Can you resend me the copy of my level that you fixed the script in ? thanks 

I have nothing "fixed", I just tried to "manually set" the value 0 to the variables and nothing else, not to mention that on my end it works even without any adjustment.

 

I suggest you to take a better look at what you're doing with sectors, teleports, monster placement etc. because the script is fine (except for what Chubz said with the killcount2 variable), though the second one will never execute: the wall that should let the cyberdemons out (which are the monsters with the second script action) will never lower, because the line with that action is behind some tagged bars that are not linked to anything on the map (nor script).

 

Looking at the stuff around, it looks like there are a couple of these kind of issues, like over 40 monsters stuck in a 64x64 sector multiple times... 

 

Share this post


Link to post
  • 0
46 minutes ago, Kan3 said:

Looking at the stuff around, it looks like there are a couple of these kind of issues, like over 40 monsters stuck in a 64x64 sector multiple times... 

 

It seems that 2 of those doors you speak of are opening at the same time , when only 1 of them is supposed to open and the other isn't supposed to open until all the enemies behind door 1 are dead but I kill a few guys in horde 1 and horde 2's already teleporting out ... IDK why there separate sectors with there own tags even , And I can't figure it out , I've updated the link to my map , if you can take a look at my scripts I'll appreciate it thanks...  

Edited by PITTSBURGH PENGUINS

Share this post


Link to post
  • 0

I've changed some things in my map , I think it's better now , but once again guess what's wrong ? that's right another script error :( But this time it's when I kill 1 monster rather than all 53 3 bars raise up when 1 monster is killed it's supposed to wait till all 53 monsters are dead , my script clearly says...

 

int roundup = 53;
int takenout;

script "Enemy Death Monitor 3" (void)
{
    killcount++;

    if (roundup >= takenout)
    {
        Door_Open (19, 64, 0);
    }
}

 

and no matter what I do it doesn't work ... And obviously IDK why , check out the map here to see if you can figure out the problem 

and if you do please let me know what it is thanks 

https://www.mediafire.com/file/5325jg13l134187/map10.wad/file

 

Share this post


Link to post
  • 0

I believe that the fact that we couldn't help you properly yet is because we didn't really understand what it's supposed to happen x)

I'll take a look

 

Quote

3 bars raise up when 1 monster is killed it's supposed to wait till all 53 monsters are dead , my script clearly says...

It clearly says:

Quote

 if (roundup >= takenout)

and

Quote

int roundup = 53;
int takenout;

so of course it runs when you kill 1 only monster, switch the ints in the if statement

Share this post


Link to post
  • 0
27 minutes ago, Kan3 said:

I believe that the fact that we couldn't help you properly yet is because we didn't really understand what it's supposed to happen x)

I'll take a look

 

It clearly says:

and

so of course it runs when you kill 1 only monster, switch the ints in the if statement

Ok thanks , I totally overlooked that LOL oops...

But I just tried switching them around , and now the bars don't open at all even after I've killed all 53 ? I don't get it I'll take a look at it and see what the problem could be , otherwise I really don't know ?

Here I've updated the map 10 package again check it out here 

https://www.mediafire.com/file/5325jg13l134187/map10.wad/file

and as always thanks for all the help :)

Edited by PITTSBURGH PENGUINS

Share this post


Link to post
  • 0

Alright, I spotted 2 main issues with the usage of the scripts:

  1. Again, you're incrementing the wrong variable, you should increment takenout in your third script, not killcount again.
  2. You cannot run that script multiple times at once. Since you've opted to the script every time a specific monster dies, you'll have troubles when more than 1 monster dies in the same instant and since these monsters are just hitscanners with low health, it's quite easy to kill them in groups, especially with a rocket launcher, so the script will run only once when you kill 2 or more dudes at the same time, ruining the counter.

To fix the second point you have 2 options:

  1. Change the action to "Script Execute Always", this will get rid of the issue, but it still wouldn't be an optimal way to do this stuff.
  2. Change the script: you've already gave those hitscanners a tid, so you can just use ThingCount() in a while loop to constantly check how many monsters with the same tid are alive and open the door when they're all dead. Something like this: 
script "EnemyCount" OPEN { //they already passed you the documentation about various type of script, so choose the one you "like".
	while(ThingCount(T_NONE, 17) > 0) {
		Delay(35);
	}
	Dostuff();
}

 

This will fix the scripting (I would use this same script for the other 2 instances as well, replacing them), though the map is quite full of critical points that may result into real issues later on...

For example: if the player decides to not shoot in the first 2 rooms, the monsters in the closets won't wake up, so the map will break.

Then again, it's never a wise choice to pile up monsters in the same spot, they can glitch out or get stuck forever.

Also, if some of the monster escape the teleport lines, he will start to roam in the room forever, unless he will luckily get on the right lines again, again breaking the map.

I suggest you take this stuff into account, but the decision is yours.

Share this post


Link to post
  • 0
4 minutes ago, Kan3 said:

Alright, I spotted 2 main issues with the usage of the scripts:

  1. Again, you're incrementing the wrong variable, you should increment takenout in your third script, not killcount again.
  2. You cannot run that script multiple times at once. Since you've opted to the script every time a specific monster dies, you'll have troubles when more than 1 monster dies in the same instant and since these monsters are just hitscanners with low health, it's quite easy to kill them in groups, especially with a rocket launcher, so the script will run only once when you kill 2 or more dudes at the same time, ruining the counter.

To fix the second point you have 2 options:

  1. Change the action to "Script Execute Always", this will get rid of the issue, but it still wouldn't be an optimal way to do this stuff.
  2. Change the script: you've already gave those hitscanners a tid, so you can just use ThingCount() in a while loop to constantly check how many monsters with the same tid are alive and open the door when they're all dead. Something like this: 

script "EnemyCount" OPEN { //they already passed you the documentation about various type of script, so choose the one you "like".
	while(ThingCount(T_NONE, 17) > 0) {
		Delay(35);
	}
	Dostuff();
}

 

This will fix the scripting (I would use this same script for the other 2 instances as well, replacing them), though the map is quite full of critical points that may result into real issues later on...

For example: if the player decides to not shoot in the first 2 rooms, the monsters in the closets won't wake up, so the map will break.

Then again, it's never a wise choice to pile up monsters in the same spot, they can glitch out or get stuck forever.

Also, if some of the monster escape the teleport lines, he will start to roam in the room forever, unless he will luckily get on the right lines again, again breaking the map.

I suggest you take this stuff into account, but the decision is yours.

Ok Thanks man , I really appreciate all your help :) If it wasn't for you I probably wouldn't have figured half the stuff wrong with my map 

so once again thanks :)

Share this post


Link to post
  • 0
1 hour ago, PITTSBURGH PENGUINS said:

Ok Thanks man , I really appreciate all your help :) If it wasn't for you I probably wouldn't have figured half the stuff wrong with my map 

so once again thanks :)

No problem, we've all been there in our "mapping career" x)

Share this post


Link to post
  • 0

OK I found the problem and now it works , the problem was that I still had Killcount++;

When rather it needed to look like this

int roundup = 53;
int takenout;

script "Enemy Death Monitor 3" (void)
{
    takenout++;

    if (takenout >= roundup)
    {
        Door_Open (19, 64, 0);
    }
}

 

So I just changed it to takenout++; and now it works that was simple , I'm gonna test and see if this works , I'll give you feedback if any other problems occur and as always thanks:)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...