xboxscene.org forums

Author Topic: For/next And Gosub/return  (Read 101 times)

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
For/next And Gosub/return
« on: December 16, 2003, 05:38:00 PM »

CODE

FOR = TO [STEP ]
:   :
[BREAK]
:   :
NEXT


Where:
is the name of the var to track the value (Incremented on NEXT)
is the value assigned to the named variable the first time through.
is the value is compared against on "next" - if it's greater, ActionScript continues AFTER the NEXT
is an optional increment (or decrement, if is greater than ) on each NEXT

BREAK skips to the appropriate NEXT and exits the loop prematurely.



So that's FOR/NEXT operation in a nutshell. It should clean up code nicely...


CODE

GOSUB


There you go. I might do DO/WHILE if I get around to it....
Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #1 on: December 16, 2003, 06:16:00 PM »

Quick q: Is recursion supported?
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
For/next And Gosub/return
« Reply #2 on: December 16, 2003, 06:26:00 PM »

CODE

FOR index = 1 to 3
FOR innerindex = 5 to 7
CallScript _DisplayMessageBox "Nested: %innerindex% %index%"
GOSUB MySub
NEXT
NEXT
QUIT
:MySub
CallScript _DisplayMessageBox "GoSub: %innerindex% %index%"
RETURN


The above should work fine.

Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #3 on: December 16, 2003, 10:01:00 PM »

tongue.gif *

SETVAR N 5
SETVAR result 1
GOSUB Factorial

:Factorial
MUL result %N%
SUB %N% 1
IF# N==1 GOTO Blah
GOSUB Factorial
Blah:
RETURN
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
For/next And Gosub/return
« Reply #4 on: December 17, 2003, 01:26:00 AM »

QUOTE (geniusalz @ Dec 17 2003, 02:01 AM)
Heh. I asked whether nested FOR loops are supported in the other thread, but here I asked for recursion here.

Like recursive factorial computation

* Ignore all the syntax errors  tongue.gif *

SETVAR N 5
SETVAR result 1
GOSUB Factorial

:Factorial
MUL result %N%
SUB %N% 1
IF# N==1 GOTO Blah
GOSUB Factorial
Blah:
RETURN

That should work.... as long as you don't overflow the stack (speaking of which, when you do that at the moment, bad things will probably happen.)

I will probably limit the stack to soem arbitrary limit before release.
Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #5 on: December 17, 2003, 09:57:00 AM »

ph34r.gif .  But I don't know what use the exploits will be. laugh.gif  But good to see a responsible programmer taking care of this  wink.gif
::end of rambling
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
For/next And Gosub/return
« Reply #6 on: December 17, 2003, 10:23:00 AM »

QUOTE (geniusalz @ Dec 17 2003, 01:57 PM)
Bad things.  Now I see how exploits work.  So you could have people writing exploits for MXM if it didn't prevent stack overflows ph34r.gif .  But I don't know what use the exploits will be. laugh.gif  But good to see a responsible programmer taking care of this  wink.gif
::end of rambling

Heh heh, well, it would take quite a bit to cause a problem, but an infinite recursion would definitely mess up the system.

It might just error out, though...

I think I'll set the limit to 1000. Sound good?
Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #7 on: December 17, 2003, 10:27:00 AM »

1000 sounds good
Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #8 on: December 17, 2003, 10:32:00 AM »

As for the if blocks, they can be easily converted to a whole slew of GOTO statements.  I wrote a little prog to do this, but right now it has problems recognizing code blocks (inside ifs) more than a line long.

Update: Fixed that bug, click to download MXM Scripter pre-alpha 1.1
Logged

geniusalz

  • Archived User
  • Hero Member
  • *
  • Posts: 1635
For/next And Gosub/return
« Reply #9 on: December 17, 2003, 03:05:00 PM »

It's all for scripting.
Sort of like BASIC programming.
You can do stuff like write/read xml files through scripting, copy/delete/renames files and folders, display stuff on the screen.  Basically a limited programming language for the xbox that is easy to learn, that runs inside MXM.

In other words, don't worry about it, as you can use MXM without knowing any of this.
Logged

Infared

  • Archived User
  • Newbie
  • *
  • Posts: 28
For/next And Gosub/return
« Reply #10 on: December 22, 2003, 04:10:00 AM »

laugh.gif
Logged