Question about the use of I (solved)

Started by Annonymus, December 23, 2013, 04:43:25 PM

Previous topic - Next topic

Annonymus

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?
If a topic started by me is in the wrong place feel free to move it at anytime.

Michionlion

#1
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.
"Remember kids, the only difference between science and messing around is writing it down."
                                                                                                                         - Adam Savage

My website
My CW1, and CW2 maps!

Annonymus

#2
 :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??  ???
If a topic started by me is in the wrong place feel free to move it at anytime.

Grayzzur

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".
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Annonymus

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.
If a topic started by me is in the wrong place feel free to move it at anytime.

Grauniad

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."
A goodnight to all and to all a good night - Goodnight Moon

thepenguin

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.
We have become the creeper...

Grayzzur

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.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker