Robot Battle Home Log In | Register
Welcome Guest
Help | Search | Members | Contest Calendar | Chat

Robot Battle Registry  Discussion Forums  Robot Creation  Section Names And Indexes
 
Section Names And Indexes Track this topic | Email this topic | Print this topic 
just.monkey.code
Posted: Jun 26 2011, 06:58 PM


Player


Group: Just Joined
Posts: 18 (3 robots)
Member No.: 1672
Joined: 26-June 11



From the Tinybot 101 tutorial on the Wiki, I learned that sections may be referenced by name or by index. While I see that this is old news around here, this opens a lot of possibilities for things like psuedo-local variable scopes via stacks and interesting control flow options I would like to explore. After having searched the Regestry and scoured the help files, I can find no other reference to section indexes, but I am left with a lot of questions. First, are these indexes to an array that we have access to? Second, is there any way to get the section name associated with a given index?

Somewhat related is the _stack, which stores the names of sections as strings. Is there anyway to convert these strings back to lvalues? Consider:
RSL
WierdFunc {
  if(someTestToStopAnInfinateLoop)
     GoSub(_stack[1])
  endif
}

While I know that this does not work, is there anything I can do with _stack[1] that is along these lines? Just to show that I've done my homework before posting, what follows is the results of some of my experimentation. I have noted which work and which don't.

The following happily stores the values 1 and 3 into the expected elements.
RSL
anArray[SomeFunc] = 1
anArray[SomeOtherFunc] = 2


This sets someVar to 1 assuming the previous lines have run.
RSL
someVar = anArray[SomeFunc]


This sets someVar to 3:
RSL
someVar = anArray[SomeFunc] + anArray[SomeOtherFunc]


But before you get to comfortable, the following line generates an "Unknown variable" error. Note that in the previous example there were two different names, whereas in this one there is only one name used twice.
RSL
someVar = anArray[SomeFunc] + anArray[SomeFunc]


This results in an "Invalid Section" error, even when there are more than 2 sections defined:
RSL
GetRandom(1)
GoSub(_random + 1)


Somewhere in all this playing around, I even got a "2 values" error, or something to that effect, but I have not been able to repeat that.

I would appreciate any insight into this which the Registry may provide, and I thank you for bearing with my long windedness.
 
    Top

chess123mate
Posted: Jul 15 2011, 12:02 PM


Logical Programmer


Group: Members
Posts: 588 (24 robots)
Member No.: 936
Joined: 3-February 07



Wow, never knew this. If you could use the gosub() in the way you suggested, that would be very interesting for adapting bots.

Of course, I have no idea how to answer your questions... hopefully someone else might have experience with this?
 
     Top

steJ
Posted: Jul 17 2011, 01:38 PM


Tiny Bot Obsessive


Group: Moderators
Posts: 953 (13 robots)
Member No.: 9
Joined: 2-May 03



did you try rounding the reuslt at all? maybe its trying to run sub 1.5 or something

--------------------
He who laughs last, thinks slowest.
SteJ
 
    Top

just.monkey.code
Posted: Jul 18 2011, 01:56 PM


Player


Group: Just Joined
Posts: 18 (3 robots)
Member No.: 1672
Joined: 26-June 11



I didn't think of rounding the first time around. The values that are on the stack are the string names of the sections. But on your suggestion, I gave it a try anyway (thinking that there may have been a quirk of parsing that would have resulted in either the section name as an lvaule or the index itself), but alas, rounding did not work. The following code would have resulted in an infinite loop if the rounding trick would have worked. Instead it yielded an invalid string parameter for the round function.
RSL
Init {
   regcore(HardCore)
}
HardCore {
   round(_stack[0], 0)
   gosub(_result)
}

This is what I expected since, again, it's the names of the sections which are stored on the stack. In this case the round function was trying to resolve to
RSL
round("hardcore", 0)
 
    Top

<< Back to Robot Creation