UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Stop a loop?

broken avatar :(
Created 7 years ago
by Doodles_Inc
0 Members and 1 Guest are viewing this topic.
1,926 views
broken avatar :(
×
broken avatar :(
Location: br
Date Registered: 20 April 2016
Last active: 2 years ago
Posts
145
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
Personal Quote
if I surprised you, you had underestimated me
Signature
if I surprised you, it was because you underestimated me
×
Doodles_Inc's Groups
Doodles_Inc's Contact & Social LinksdoodlescriminoserDoodles_IncDoodlesInc
You might think that this is a joke, but, I really suck at scripting since I started it this week, and I need help so, after the loop is completed, he stops, thanks in advance!
If you're wondering how my code is looking... here it is: https://pastebin.com/dJ45jkGa

Double Post Merge: September 16, 2017, 10:54:21 pm
Made it, you can see it in my pastebin.
Last Edit: September 16, 2017, 10:54:21 pm by Doodles_Inc
This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 28 June 2015
Last active: 4 years ago
Posts
72
Respect
Forum Rank
Rotting Walker
Primary Group
Member
×
Wolfilms's Groups
Wolfilms's Contact & Social Links
It looks like you are waiting for a player to enter 2 zones at once?
broken avatar :(
×
broken avatar :(
Location: br
Date Registered: 20 April 2016
Last active: 2 years ago
Posts
145
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
Personal Quote
if I surprised you, you had underestimated me
×
Doodles_Inc's Groups
Doodles_Inc's Contact & Social LinksdoodlescriminoserDoodles_IncDoodlesInc
It looks like you are waiting for a player to enter 2 zones at once?
Not at once, I managed to finish the script, I was only waiting for someone to answer so I could put this thread as solved.
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 28 June 2015
Last active: 4 years ago
Posts
72
Respect
Forum Rank
Rotting Walker
Primary Group
Member
×
Wolfilms's Groups
Wolfilms's Contact & Social Links
oh ok
Marked as best answer by Doodles_Inc 6 years ago
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
Signature
Let he who has not sinned cast the first stone.
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
I know you solved the issue, but I don't think you fully understand how while() loops work. Figured I'd explain a little to help you out.

Everything inside {curly braces} will loop forever until while(true) is evaluated as false - unless you call a break. It will work the way you're doing it (saw the pastebin, lol btw) however it is completely unnecessary if you call a wait() statement.

Basically, loops in general are intended to repeat or iterate a block of code until some condition is met. Logically if you're waiting() for a zone entrance, what code do you need to repeat? None. When you call waittill("zone_enter"), the script halts and does not process the next line until that notification is recieved, thus making a loop irrelevant. Then the next waittill("zone_enter") gets called and halts again until the player enters. So just get rid of the loop altogether, and write your code as normal. Ill give you a few examples for the sake of it. I'm no expert coder, but I can teach what I know.

Code Snippet
Plaintext
//This example counts 10 player slide actions, prints the total to the screen, then breaks out of the loop & ends the function.
function example_loop()
{
slides = 0;
max_slides = 10;
players = GetPlayers();
player = players[0];

while(1)
{
if(player isSliding())
{
slides++;
IPrintLnBold("[" + slides + "] Slides have been detected");
if(slides >= max_slides)
{
break;
}
}
wait(1);
}
}

//This ex. uses a for() loop, counts & prints the array of zombies alive. You don't need a break statement as 'i' counts up with zombies.size.
//Once 'i' is greater than zombies.size, then middle statement in the loop becomes false, breaking the loop.
function example_loop2()
{
zombies = GetAISpeciesArray("axis", "all");

for(i = 0; i < zombies.size; i++)
{
IPrintLnBold("[" + i + 1 + "] zombies have been detected");
}

}

//Or you could do
function example_loop3()
{
i = 0;
foreach(zombie in GetAISpeciesArray("axis", "all"))
{
IPrintLnBold("[" + i + 1 + "] zombies have been detected");
i++;
}
}
Last Edit: November 30, 2017, 04:14:42 am by Archaicvirus

 
Loading ...