Get values of other pawns through simkin command?

Topics regarding Scripting with Reality Factory
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Re: Get values of other pawns through simkin command?

Post by QuestOfDreams »

Juutis wrote:
Graywolf wrote:Those "for each in" commands are very convenient.
Could you explain a little what this command does and how to use it? I read about it in the Simkin docs but couldn't quite understand it. The example they have doesn't really help... :?
I'll try to explain: If you have a list/array of items you can loop through its elements either by starting with the first index and go on until you reach a max. index, e.g. simply an array of numbers

Code: Select all

for itemindex=0 to 10
{
    // you may use 'itemindex' to access an element in your itemlist
    itemlist[itemindex] = itemlist[itemindex] + 1;
}
or you can loop over all elements by using

Code: Select all

for each item in itemlist
{
    // 'item' is an element of your itemlist
    item = item + 1;
}
Using the 'for each in' method you don't need to know the maximum index of your list and you automatically get the next element in your itemlist in each iteration.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Get values of other pawns through simkin command?

Post by Juutis »

Oh, now I get it. Thanks QoD! :)
Pain is only psychological.
User avatar
Graywolf
Posts: 75
Joined: Mon Apr 14, 2008 8:36 pm
Location: Anchorage, Alaska
Contact:

Re: Get values of other pawns through simkin command?

Post by Graywolf »

There is also a built-in field for trees(arrays), called "numChildren", which gives you just that.

Code: Select all

{

	Array
	{
		thing1 [0]
		thing2 [1]
		thing3 [2]
		thing4 [3]
	}
		
	LoopThroughArray[()
	{
		for index = 0 to Array.numChildren - 1
		{
			debug(Array[index]);
		}
	}

}
In this case numChildren = 4. We have to subtract 1, because the array indices start at zero.
"So, what's the life of a programmer like?" "...Huh? What life?!"

RF System X:
http://www.realityfactory.info/forum/vi ... f=9&t=3599
Post Reply