Source language: Translate to:

New command suggestion: Die

Post your suggestions for future versions of NeoBook

Moderator: Neosoft Support

New command suggestion: Die

Postby dpayer » Fri Jan 04, 2013 9:22 am

Maybe it is simply my way of coding but I am finding the NB syntax of IF/Else/ENDIF causes me to force my code to APPEAR in a certain manner for clarity and readability.

Example: I want to check if a condition is met. If it is met I will do and extensive process. If it is not met, I want to do nothing or create the means for the user to go back and verify the condition with additional input.

This requires formating like this:
Code: Select all
If "x" "<>" "y"
  Alertbox "Error" "Opps! Condition not met"
  Else

. 100 lines of code here with many additional indents to match up IF/Endif statements throughout the code, all needing to line up right so I can tell if I close everything properly

Endif


Wouldn't it be simpler to have something like:
Code: Select all
If "x" "<>" "y"
    Alertbox "Error" "Opps! Condition not met"
    Die
Endif

. 100s of line of code . . .
 


Die would mean: end this portion of the script. (maybe another name like 'endscript' or something would be clearer, not sure). Technically, you wouldn't really need to close the IF out (with an EndIF statement) if the script dies/ends at that point.

It would contain coding much better and we would not be in a position to have to align multiple IF/Else/Endif statements in absolutely vertically aligned segments of code.

If there are suggestions of how I can improve my methodology, I'm open and would appreciate comments to that effect here.

To emulate this idea, I have begun to use GoToLines (I know Gaev, they're not preferable!). I put an endofscript line marker at the bottom of a code segment and then if I want the script to die, I just go there. It works for me.
Code: Select all
If "x" "<>" "y"
     Alertbox "Error" "Opps! Condition not met"
     GoToLine "endofscript"
Endif

.  100s of lines of code . . . . .
 . . . . .

.last line below
:endofscript
 
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: New command suggestion: Die

Postby dec » Fri Jan 04, 2013 9:32 am

Hello,

Maybe you can use the "Return" command like "Die"? From the "Return" command help:

Exit the current Action script or subroutine and return control to the previous one


In fact, supose the bellow code is place into the "Enter page" actions:

Code: Select all
AlertBox "Hello!" "Hello there!"

Return

AlertBox "Hello again!" "Well,... sorry I did not appear :("


As you can see if execute the above code, the first "AlertBox" appear like expected, but, the second one never appear, since we use the "Return" command before. I'am not really sure if you desire something like this or maybe other thing...
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: New command suggestion: Die

Postby dpayer » Fri Jan 04, 2013 10:19 am

dec wrote:Hello,

Maybe you can use the "Return" command like "Die"? From the "Return" command help:


Good suggestion David. It does work as you describe. It would be nice if we could give that command an alias to use when applied in a non standard way (example: 'endscript' as an alias for 'return')

David P.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: New command suggestion: Die

Postby Gaev » Fri Jan 04, 2013 10:20 am

If you have 100's of lines of code, best option would be to place them in a subroutine ... and do a GoSub from the main routine ... you can place as many Return commands in the subroutine as required ... and you can split the 100's of lines into even more (nested, better managed) subroutines.

You might also look into the use of ...

Code: Select all
While (condition here)
    .... commands here
    ExitWhile
    ... more commands here
    ExitWhile
    ... more commands here
    ... set 'condition' to be 'not true' here if you just want to loop through one time
EndWhile
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: New command suggestion: Die

Postby dpayer » Fri Jan 04, 2013 12:28 pm

Gaev wrote:If you have 100's of lines of code, best option would be to place them in a subroutine


Normally true. I am attempting to make a function I can share with others here. The function must be self contained.

David
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: New command suggestion: Die

Postby Wrangler » Sat Jan 05, 2013 9:27 am

Gotoline can also come in handy for certain situations:

If "x" "<>" "y"
Alertbox "Error" "Opps! Condition not met"
Gotoline "end"
endif

. 100s of line of code . . .




:end
... more code if needed
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA


Return to NeoBook Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests