-2

I was looking for the cleanest way to accomplish writing $2 to a text file the amount of times specified. I'm sure this is possible and i will provide and example to what I am looking for...

 on *:text:*write*:?: { write test.txt $2 "$3 times"}

so, for an example, the user would type

write Hello 3

this would write hello on 3 lines to test.txt, the contents should be as following in test.txt

Hello
Hello
Hello

Thank you!

The way I would have approached this is with a timer, I don't really know an easier way. Anyways, I posted this looking for the CORRECT way to do this or at least the most clean.

skdfsfwse
  • 19
  • 7
  • To my knowledge, using a timer is the best way to achieve this. – Denny Sep 07 '16 at 20:00
  • @Denny Alright, that seemed like my best bet anyways, I was just looking to see if there was something i was missing, thanks for confirming! – skdfsfwse Sep 07 '16 at 22:53
  • A timer may be the way to achieve what you are looking for (and shortest), but it's far from being the best approach. A better approach will be the snippet Sirius_Black posted, using a while loop. – Orel Eraki Sep 10 '16 at 12:11

1 Answers1

1

if you want an instant answer instead of waiting timers, you can use while loops

on *:text:*write*:?: { 
var %x = 1
while (%x <= $$3) {  
write test.txt $2
inc %x
}
}
Sirius_Black
  • 471
  • 3
  • 11