Looping Scripts

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Looping Scripts

Post by dbj87jb »

I'm trying to get a looping rocket drop, to use as a trap, but every time it either doesn't work (runaway script) or those that have done, only drop once and then won't loop after the first drop.

What's working-

Code: Select all

Script 5 open //Rocket Drop
{
int sid = 0;  // sid is the sector ID

     for ( sid = 11; sid < 12; sid++ )  // sid is the sector ID
	{
SpawnProjectile(9,"Rocket",0,0,64,5,0);
delay (35);	
sid++;
	}
}
What's not working-

Code: Select all

Script 5 open //Rocket Drop
{
int sid = 0;  // sid is the sector ID

     for ( sid = 11; sid < 11; sid++ )  // sid is the sector ID
	{
SpawnProjectile(9,"Rocket",0,0,64,5,0);
delay (35);	
sid++;
	}
}
I've also tried While & For script layouts. Only managed to get While Script set up to work (actually drop something when it isn't failing as a "Runaway script"), followed the examples and guidelines on the website but it's not looping. 9 is the Teleport/Map Marker from which the rockets drop from, 11 is the Sector.

While-

Code: Select all

Script 5 open //Rocket Drop
{
int sid = 11;  // sid is the sector ID

    While ( sid < 11 );
	{
SpawnProjectile(9,"Rocket",0,0,32,1,0);
delay (35);	
sid++;
	}
}
Drops once, then stops. Changed While ( sid < 11 ); to While ( sid < 12 ); it fails.
Last edited by dbj87jb on Tue Feb 23, 2016 9:10 am, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49238
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Looping Scripts

Post by Graf Zahl »

Of course the second one is not working. You are trying to count from 11 onwards, as long as the number is smaller than 11. And since 11 is not smaller than 11 it just skips over it.


And please learn proper formatting!
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

Graf Zahl wrote: And please learn proper formatting!
Sorry I'm not a friggin genius like you're making out you are! Perhaps if there was some simplified examples I wouldn't be asking for advice-- especially not from people like you :evil:
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

[quote="Graf Zahl"]Of course the second one is not working. You are trying to count from 11 onwards, as long as the number is smaller than 11. And since 11 is not smaller than 11 it just skips over it.

Code: Select all

Script 5 open //Rocket Drop
{
int sid = 11;  // sid is the sector ID

    While ( sid < 9 );
   {
SpawnProjectile(9,"Rocket",0,0,32,1,0);
delay (35);   
sid++;
   }
}
Lower numbers aren't working either by the way... ^^ Lower then 9? Not working

Code: Select all

{
int sid = 0;  // sid is the sector ID

     for ( sid = 11; sid < 13; sid++ )  // sid is the sector ID
   {
SpawnProjectile(9,"Rocket",0,0,64,5,0);
delay (35);   
sid++;
   }
}
^^ Lower then 13? Not working!!!
User avatar
Caligari87
Admin
Posts: 6236
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Looping Scripts

Post by Caligari87 »

Image

8-)
User avatar
A-Bomb
Posts: 16
Joined: Sun Feb 21, 2016 4:56 pm
Location: Glengary, WV, US

Re: Looping Scripts

Post by A-Bomb »

So, a couple things:

Code: Select all

     int sid = 0;  // sid is the sector ID

     for ( sid = 11; sid < 13; sid++ )  // sid is the sector ID
     {
         SpawnProjectile(9,"Rocket",0,0,64,5,0);
         delay (35);   
         sid++;
     }
1) Why exactly are you incrementing

Code: Select all

sid
twice in the loop? It just runs once.
2) I don't think you're using this loop for the same thing that you want it to do.

What I THINK (although, I could be wrong because I still don't exactly know what you're trying to achieve) you'd want is maybe something more like:

Code: Select all

     int sid = 11;  //it looked like you wanted this to stay at 11 while something else "looped" ie the rockets spawning
     int rocketsYouWantToFire = someNumber; //how many rockets
     for ( int i = 0; i < rocketsYouWantToFire; i++ )
     {
         SpawnProjectile(9,"Rocket",0,0,64,5,0);
         delay (35);
     }
Let me know if I understand what you're trying to do please.
arkore
Posts: 25
Joined: Wed Nov 27, 2013 8:27 pm

Re: Looping Scripts

Post by arkore »

A-Bomb wrote: 1) Why exactly are you incrementing

Code: Select all

sid
twice in the loop?
Because as you saw earlier, he's new to programming -- and even if you didn't see earlier, it's still obvious he's new. So, don't ask rhetorical "why" questions; that's rude.


dbj, your for() loop already has sid++ in it, which increments sid on each iteration/loop.

You also have an extra "sid++" in your code too. Remove that.

Code: Select all

int sid = 0;  // sid is the sector ID

for (sid = 11; sid < 13; sid++) {
  SpawnProjectile(9, "Rocket", 0, 0, 64, 5, 0);
  delay(35);   
}
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Looping Scripts

Post by randi »

dbj87jb wrote:

Code: Select all

While ( sid < 11 );
That semicolon doesn't belong there.
User avatar
A-Bomb
Posts: 16
Joined: Sun Feb 21, 2016 4:56 pm
Location: Glengary, WV, US

Re: Looping Scripts

Post by A-Bomb »

arkore wrote: Because as you saw earlier, he's new to programming -- and even if you didn't see earlier, it's still obvious he's new. So, don't ask rhetorical "why" questions; that's rude.
dbj87jb and arkore, I'm sorry if I came off as rude (I legitimately didn't think my response could have been interpreted in such a way!). When I asked the question I was trying to get the "intended" purpose for which the extra statement was placed there in hopes of better understanding the goal (as well as understanding what the op "thought" was going on so as to provide an even better follow up response). It was not rhetorical in any sense, however I'll be sure to exhibit a tad more scrutiny with regards to my words before I post. Anywho sorry again, I hope you get this issue under control :) .
arkore
Posts: 25
Joined: Wed Nov 27, 2013 8:27 pm

Re: Looping Scripts

Post by arkore »

I'm sorry too then. I understand what you're saying, and realize you meant no harm.

Far too often I see people asking those kind of "why" questions that are typically of condescending nature.

My bad.

Thanks,
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

A-Bomb wrote: Let me know if I understand what you're trying to do please.
I'm trying to make a looping script-- where a projectile (In this case a Rocket) spawns from a set location/Map Spot & falls to the floor then drops another after a 1-3 second delay (depending on how fast it goes from A to B). As everyone can obviously see, yes, this is my first "proper" attempt (have tried in the past but couldn't figure it out then) at using a looping style script. Decided to try using one of these for setting traps, instead of having to re-trigger the script's action via switches, killing something or walking in or out of marked sectors or crossing sector lines that would just trigger the script, because it's inconsistent.

What's been happening with the scripts that do spawn the Rockets, is that they spawn once then stop-- reading the feedback here, a lot of you have pointed out areas that need changing, I was working around the Looping Script examples on the ACS ZDoom Wiki, partly one of the reasons why it's been too confusing for me to figure out what to do, but I'll go back with a slightly better understanding of what I was doing wrong and try again now.

Thanks again to everyone for the feedback.
Last edited by dbj87jb on Tue Feb 23, 2016 3:12 pm, edited 1 time in total.
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

The only thing that has really "annoyed" me, is this "And please learn proper formatting!" I find it incredibly disrespectful when people talk down to others, like they're an idiot, because they don't understand something, instead of leaving some constructive criticism or advice...

When people ask questions, at least I can sit back and think about what they are trying to say. But there is also misinterpretation to take on board, and there's a highly likely chance that somehow, I've misread that as being something else instead of arrogance. Either way, I'd also like say sorry and thanks again.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Looping Scripts

Post by wildweasel »

dbj87jb wrote:The only thing that has really "annoyed" me, is this "And please learn proper formatting!" I find it incredibly disrespectful when people talk down to others, like they're an idiot, because they don't understand something, instead of leaving some constructive criticism or advice...

When people ask questions, at least I can sit back and think about what they are trying to say. But there is also misinterpretation to take on board, and there's a highly likely chance that somehow, I've misread that as being something else instead of arrogance. Either way, I'd also like say sorry and thanks again.
Would you mind terribly if I point people to this post in the future? I'm trying to make a case for politeness and courtesy being more important than simply being correct, and this is a perfect example of why. (Sorry, Graf, but you're kind of part of this example too...)
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

[/quote]
Would you mind terribly if I point people to this post in the future? I'm trying to make a case for politeness and courtesy being more important than simply being correct, and this is a perfect example of why. (Sorry, Graf, but you're kind of part of this example too...)[/quote]

WildWeasel, All I did was ask what I was doing wrong. But I know when I've stepped out of line and I admit that my actions or reactions to Graf's comments aren't justifiable. I don't want to be in the "spotlight" but, if this sets an example on how things should and should not be carried out, then by all means, please do.
dbj87jb
Posts: 95
Joined: Tue Nov 04, 2014 8:59 am

Re: Looping Scripts

Post by dbj87jb »

wildweasel wrote:
dbj87jb wrote:The only thing that has really "annoyed" me, is this "And please learn proper formatting!" I find it incredibly disrespectful when people talk down to others, like they're an idiot, because they don't understand something, instead of leaving some constructive criticism or advice...

When people ask questions, at least I can sit back and think about what they are trying to say. But there is also misinterpretation to take on board, and there's a highly likely chance that somehow, I've misread that as being something else instead of arrogance. Either way, I'd also like say sorry and thanks again.
Would you mind terribly if I point people to this post in the future? I'm trying to make a case for politeness and courtesy being more important than simply being correct, and this is a perfect example of why. (Sorry, Graf, but you're kind of part of this example too...)

WildWeasel, All I did was ask what I was doing wrong. But I know when I've stepped out of line and I admit that my actions or reactions to Graf's comments aren't justifiable. I don't want to be in the "spotlight" but, if this sets an example on how things should and should not be carried out, then by all means, please do
Locked

Return to “Editing (Archive)”