Someone help me with this loop?

Discuss all aspects related to modding Zandronum here.
Post Reply
Krispy
 
Posts: 88
Joined: Tue Jun 05, 2012 9:37 pm
Location: Michigan

Someone help me with this loop?

#1

Post by Krispy » Wed Sep 26, 2012 12:52 am

I suppose what I'm trying to do should be apparent in these scripts, but I'm trying to respawn a rocketbox whenever the player's rockets get below 5.
Spoiler: A while loop (Open)
script 1 enter
{

while (CheckInventory("rocket") < 5)
{
spawnspot("rocketbox",5,0,0);
delay (200);

}
}
Spoiler: An if statement (Open)
{
if (CheckInventory("rocket") < 5)

spawnspot("rocketbox",5,0,0);
delay(200);
restart;

}
Both have the same results, that rocket boxes keep spawning no matter how much ammo I have.

User avatar
Combinebobnt
Retired Staff / Community Team Member
Posts: 1906
Joined: Mon Jun 04, 2012 3:37 am
Location: Earth
Contact:

RE: Someone help me with this loop?

#2

Post by Combinebobnt » Wed Sep 26, 2012 1:03 am

Actor is rocketammo, not rocket.

Krispy
 
Posts: 88
Joined: Tue Jun 05, 2012 9:37 pm
Location: Michigan

RE: Someone help me with this loop?

#3

Post by Krispy » Wed Sep 26, 2012 7:47 pm

Thanks. Only works on the 'if' statement for me, but that's enough!

jdagenet
Forum Regular
Posts: 192
Joined: Tue Jun 05, 2012 8:08 am

RE: Someone help me with this loop?

#4

Post by jdagenet » Tue Oct 09, 2012 4:27 am

.
Last edited by jdagenet on Sun Jul 13, 2025 5:40 pm, edited 1 time in total.

Llewellyn
Forum Regular
Posts: 578
Joined: Mon Jul 02, 2012 7:12 am

RE: Someone help me with this loop?

#5

Post by Llewellyn » Tue Oct 09, 2012 5:04 pm

jdagenet wrote: I haven't tested this but would this work?

Code: Select all

script 1 enter
{
     While (TRUE)
     {
          if (CheckInventory("RocketAmmo") < 5)
          {
               SpawnSpot ("RocketBox", 5, 0, 0);
               Delay (200);
          }
     }
}
Besides bumping the topic after the problem was solved:
No that would not work, your Delay is inside the IF statement, the script would run-away as soon as you had more than 5 rocketammo in your inventory.

You would want this if you wanted it to check every 200 tics and spawn a box:

Code: Select all

script 1 enter
{
	if (CheckInventory("RocketAmmo") < 5)
		SpawnSpot ("RocketBox", 5, 6, 0);
	Delay(200);
	restart;
}
or this if you wanted it to only spawn one box and wait 200 tics to spawn another:

Code: Select all

script 1 enter
{
	if (CheckInventory("RocketAmmo") < 5 && !ThingCount(T_NONE, 6))
	{
		SpawnSpot ("RocketBox", 5, 6, 0);
		Delay (200);
	}
	else
		Delay(1);
	restart;
}
Last edited by Llewellyn on Tue Oct 09, 2012 5:09 pm, edited 1 time in total.

Post Reply