Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Annonymus on December 23, 2013, 04:43:25 PM

Title: Question about the use of I (solved)
Post by: Annonymus on December 23, 2013, 04:43:25 PM
If I use I inside a function, like this:

1 10 do
@createI
loop

:createI
I 1 eq if
@create1
endif

I 2 eq if
@create2
endif
#repeat for all numbers


does that work?
I've made something where I found no way around doing this or writing ~100 more lines of code everytime i use this, and I need to use it at least 5 times in my script... but it doesn't work so now I'm not sure if it's because of this or if there is another error I just can't find.

P.S. A do loop executes the first time for the index (in "1 10 do...loop" that would be 1) and the last time for the limit-1 (in "1 10 do...loop" that would be 9), right?
Title: Re: Question about the use of I
Post by: Michionlion on December 23, 2013, 04:46:26 PM
What you can do is push I to the stack before you call @createI, and then pop and evaluate it in the function.  Sort of like an method argument.

I have limited knowledge of CRPL, though, so you may want to get other opinions on this.
Title: Re: Question about the use of I
Post by: Annonymus on December 23, 2013, 05:03:14 PM
 :o  that's genial and easy, why didn't I think about this?
However, after I did this it still doesn't work  :(
But I'm even more puzzled now because, when I tested by inserting "CurrentCoords -200 SetCreeper" into the code at various places, I found out the script finds its way into the if...endif but not into the 1 10 do...loop inside this if statement!
to clarify, I have a code like this:

if (#condition)
                              ##the code arrives here (if i insert currentcoords -200 setcreeper it sets the creeper at the coords of the core to -200)
1 10 do
                              ##but not here (if i insert it here nothing happens...)
#code
loop

endif


how is this possible??  ???
Title: Re: Question about the use of I
Post by: Grayzzur on December 23, 2013, 05:36:52 PM
You have your do loop conditions reversed. Try "10 1 do". First number is the one to stop at, second number is the initial value, and it will increment by 1 each time through. That will run through 1-9. If you want ten iterations, it's common to say "10 0 do".
Title: Re: Question about the use of I
Post by: Annonymus on December 24, 2013, 04:50:53 AM
Thank you very much, maybe in the wiki someone should specify this, there is just written that the 2 values are limit and index without specifying which one is which.
Title: Re: Question about the use of I
Post by: Grauniad on December 24, 2013, 08:26:33 AM
Quote from: Annonymus on December 24, 2013, 04:50:53 AM
Thank you very much, maybe in the wiki someone should specify this, there is just written that the 2 values are limit and index without specifying which one is which.

The purpose of a wiki is that everyone can be "someone."
Title: Re: Question about the use of I (solved)
Post by: thepenguin on December 24, 2013, 09:51:18 AM
Quote from: Grauniad on December 24, 2013, 08:26:33 AM
Quote from: Annonymus on December 24, 2013, 04:50:53 AM
Thank you very much, maybe in the wiki someone should specify this, there is just written that the 2 values are limit and index without specifying which one is which.

The purpose of a wiki is that everyone can be "someone."

Very interesting.  I always thought that the purpose of a wiki was to provide accurate information.
Title: Re: Question about the use of I (solved)
Post by: Grayzzur on December 24, 2013, 02:30:27 PM
The existing documentation seemed clear enough to me before, but penguin's addition makes it crystal now, thanks penguin!

A note on saying "Someone should..."
QuoteThere was a task to be done. Everyone was sure that Someone would do it. Anyone could have done it, but Noone did it. Someone got angry about that because he thought that it was Everyone's job. Everyone thought that Anyone could do it, but Noone realised that Everyone wouldn't do it. In the end, Everyone was angry with Someone because Noone did what Anyone could have done.