Jump to content


Photo

For/next And Gosub/return


  • Please log in to reply
12 replies to this topic

#1 BenJeremy

BenJeremy

    X-S Elysian

  • Head Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 9,690 posts
  • Xbox Version:v1.1
  • 360 version:v1 (xenon)

Posted 17 December 2003 - 01:38 AM

Well, there are more goodies coming down the pipeline... in the "WIP" build, I now have FOR/NEXT and GOSUB/RETURN support:

CODE

FOR <var> = <start> TO <end> [STEP <stepval>]
:   :
[BREAK]
:   :
NEXT


Where:
<var> is the name of the var to track the value (Incremented on NEXT)
<start> is the value assigned to the named variable the first time through.
<end> is the value <var> is compared against on "next" - if it's greater, ActionScript continues AFTER the NEXT
<stepval> is an optional increment (or decrement, if <start> is greater than <end>) 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 <label>

:<label>
:    :
RETURN

Pretty straightforward... put subroutines in your script, stay "local" with variables and such. On "RETURN" the script will return to the line AFTER the GOSUB.



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

#2 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 02:16 AM

Quick q: Is recursion supported?

#3 BenJeremy

BenJeremy

    X-S Elysian

  • Head Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 9,690 posts
  • Xbox Version:v1.1
  • 360 version:v1 (xenon)

Posted 17 December 2003 - 02:26 AM

Yes...

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.



#4 SumDumGuy2

SumDumGuy2

    X-S Enthusiast

  • Members
  • 21 posts

Posted 17 December 2003 - 02:42 AM

Bravo... I don't know how you do it man... but anyway you slice it up, You have nudged XBMP out of my number 1 spot for favorite app and that was not easy to do, trust me... I am definitely going to have to pay your tipcup a visit when I get some change... keep up the good work beerchug.gif

#5 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 06: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

Edited by geniusalz, 17 December 2003 - 06:02 AM.


#6 BenJeremy

BenJeremy

    X-S Elysian

  • Head Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 9,690 posts
  • Xbox Version:v1.1
  • 360 version:v1 (xenon)

Posted 17 December 2003 - 09:26 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.

#7 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 05: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

#8 BenJeremy

BenJeremy

    X-S Elysian

  • Head Moderator
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 9,690 posts
  • Xbox Version:v1.1
  • 360 version:v1 (xenon)

Posted 17 December 2003 - 06:23 PM

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?

#9 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 06:27 PM

1000 sounds good

#10 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 06:32 PM

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

Edited by geniusalz, 17 December 2003 - 06:44 PM.


#11 Infared

Infared

    X-S Member

  • Members
  • Pip
  • 89 posts

Posted 17 December 2003 - 09:51 PM

hiya guys,

happy holidays,

umm im kinda a newb at this xbox stuff ... and i would like to know what this "For/next And Gosub/return" is about unsure.gif

thx pop.gif

#12 geniusalz

geniusalz

    Team MXM

  • Head Moderator
  • PipPipPipPipPip
  • 1,827 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 17 December 2003 - 11:05 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.

Edited by geniusalz, 18 December 2003 - 12:07 AM.


#13 Infared

Infared

    X-S Member

  • Members
  • Pip
  • 89 posts

Posted 22 December 2003 - 12:10 PM

o lol thx laugh.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users