Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 25th May 2018 at 1:07 AM
Default If you wanted a loop to repeat X times, how would you do it?
I have a loop that I want to repeat just 5 times (although that number might be variable)
I have a work around to make it happen, but it's much longer code than what I am sure is possible... basically, everytime it fires it sets a different 'true' depending on what is already false/true.
I've tried using alarms, which I know should work, but I am not clear on how the various alarm properties impact each time unit.
I know we discussed that in another thread some, but it's still not clear to me.

So, I was wondering if anybody had a concise solution for just this sort of specific loop they would like to share...
if you do, it would be most appreciated as all this is an ongoing learning process for me where the understanding of it has now become more of a hobby than the actual game.
Thank you!
Advertisement
Scholar
#2 Old 25th May 2018 at 3:35 PM
I don't really understand. Some context would help.

Usually we can just use for, do while, while or foreach to make something loop for X number of times.
Like
for(int i=0;i<=5;i++)
{
//your code
}
But I feel like this is not what you were looking for. So some context would help.
Test Subject
Original Poster
#3 Old 27th May 2018 at 8:44 AM
Actually, I think this is exactly what I was looking for... this basically would be used in the loop handler, correct?
So, doloop reference the loop handler, jam that down in the handler and it would count 5 shots...
Or am I missing something?
Entirely possible... I miss very basic things still sometimes.
Virtual gardener
staff: administrator
#4 Old 27th May 2018 at 10:23 AM
The Loop skydome shows is pretty much the loop that will run the same code for 5 times. There's always the switch/case one which pretty much looks through this list and stops when there's an entry that matches the input. There are about 2 other loops but I think Skydome's loop suggestion could be pretty helpful for shooting out visual effects or specific animations. (I think skills use it as well?)

Here's a really nice guide if needed: http://csharp.net-tutorials.com/basics/loops/
Test Subject
Original Poster
#5 Old 27th May 2018 at 10:05 PM
Quote: Originally posted by Lyralei
The Loop skydome shows is pretty much the loop that will run the same code for 5 times. There's always the switch/case one which pretty much looks through this list and stops when there's an entry that matches the input. There are about 2 other loops but I think Skydome's loop suggestion could be pretty helpful for shooting out visual effects or specific animations. (I think skills use it as well?)

Here's a really nice guide if needed: http://csharp.net-tutorials.com/basics/loops/


I had asked other people before to break down for(int i = 0; i < number; i++) to where I could understand how it functioned.
I had kind of given up on asking that.
This is the first time anybody has linked me something so concise that I actually have an understanding of it after reading it.
I really appreciate this... I can now use all of these without a problem and with a clear understanding of what each does in my scripts.
Thank you!
Virtual gardener
staff: administrator
#6 Old 29th May 2018 at 11:12 AM
You're welcome! To be honest, of all loops I know, that one was the hardest for me to understand too. But the great thing about knowing loops is the fact that they're pretty much the same for every other coding language. So if you were thinking of branding out on your coding languages it's much easier to follow it
Test Subject
Original Poster
#7 Old 29th May 2018 at 1:48 PM
Quote: Originally posted by Lyralei
You're welcome! To be honest, of all loops I know, that one was the hardest for me to understand too. But the great thing about knowing loops is the fact that they're pretty much the same for every other coding language. So if you were thinking of branding out on your coding languages it's much easier to follow it


I am absolutely intending to do that.
For years now, I've been tinkering with the code in sims 3, just to mess with the game some.
One day I woke up and realized I was deriving a lot of the same pleasure I get from reading while fiddling with the code.
Pop something in here, see how it works out... experiment, play around...
I had sort of let it go for a time because I hit a wall... and I am not knocking anyone at all, in the past people have tried to help... but it is only recently that something actually clicked and I realized I wasn't just stabbing around in the dark and that I actually had an understanding of it.
And, at about the same time that happened, I logged back into here and got just exactly the help I needed to answer a few other questions I have long had.
Somewhere between the straight-forward, simple explanations that also included code and phrases like 'this does that, specifically' .. all just very straightforward...
Somewhere between those events stated above, something really clicked.
I'm not just monkeying with C# (although I am not yet good at it) I am actually coding in my head while doing other activities with code I have not seen prior, but just know now that it will probably work.
I have so much to learn, but now my learning isn't just limited to screen time.
I am deeply appreciative. It's like a gift this community, and especially you guys here lately, have given me.
**Sincerely, Thank You, All!**
Scholar
#8 Old 29th May 2018 at 3:32 PM
Oh sorry I didn't check in here sooner :p

Ok I'll explain the loops.

for(int i=0;i<=5;i++)
{
print("a");// or cout<< or echo or whatever depending on the language you're using.
}

This will print
aaaaa

First i becomes 0. Then a is printed. Then i gets increment, i=i+1. After that it checks if i's calue is less than or equal to 5. If yes then the print a again. Then this process continues until i becomes 6. Because 6<=5 is false so loop ends.
Back to top