ID:153014
 
I know this is an extremely basic concept, but I can't help but wonder what the "proper" way to do this is. In case you don't understand, here is an example:

proc
askuser()
. = input("Please enter the data.")
switch(alert("Continue with this data: [.]?",,"Yes","Back","Cancel"))
if("Cancel")
return null
if("Back")
//This is what I'm asking suggestions on
else return .


This applies not only to input(), but also to html forms, etc. Basically, I want to know what some ideas are for going back and doing old things again in a proc. I've tried goto with strange results. while() seems like it might work, but be weird. I've also though about running the proc from inside the proc, but that doesn't work when it asks for input somewhere in the middle of a lengthy proc.

=$= Big J Money =$=
I usually use while, but only because I tend to ask a different question the second time through.

var/data=input("Data?")
while( alert("Data good?",,"Yes","No") == "No" )
data=input("Data not good: Data?")


Depending on the situation, though, a do-while might be better.

var/data
do
data=input("Data?")
while( alert("Data good?",,"Yes","No") == "No" )
[CODE]
proc/Inputting()
StartOver
var/X=input("BlahdyBLAH!")in list("Maybe","Wee")
if(X=="Wee")goto StartOver
//problem Solved
[/CODE]
See? :| Tags. goto TAG is how you go to a tag. just typing it in makes a tag.

I dunno how you made the showcode areas... Be sure to tell me that some time :/
In response to AJX
No-one EVER uses tags. The best way is the .() (Recur proc). So
return .()

Also, use 'dm' html tags to make 'showcode' areas.
In response to Hazman
No-one EVER uses tags. The best way is the .() (Recur proc). So
return .()


That isn't something that should be done with recursion but rather a while loop. It's bad design when a function could potentially recurse infinitely.
In response to AJX
<dm> tags make the fancy code blocks. You can hit "Reply with Quote" to see how people do things like that in their posts.

GOTO is evil. Don't use it. While loops are better.

var/newname=""
do
newname = input("Please enter a name between 2 and 20 characters long.") as text
while(length(newname)<2 || length(newname)>20)
I use a custom datum for entering large chunks of data. A proc called Display() sets up the common page elements and has an argument to indicate which page it should display. My system uses tabs to select which page to display, but you could easily change it to use "Back", "Next" and "Finish" buttons. The "Back" button would indicate to the datum that it should display the previous page, "Next" would indicate the next page, and "Finish" would finalize the datum and process it.

Here is an example of my critter design form's Display() proc:
    proc
Display(mob/M, page = "Appearance", message)
// beginning of the page
var/html = {"<html><head><title>Critter Type: [ID]</title>\
<LINK REL=stylesheet HREF='style.css' TYPE='text/css'>\
<SCRIPT TYPE=text/javascript>function chng(X) \
{document.location.href="BYOND://?src=\ref
[src]&chng="+X.name+\
"&val="+X.value;}function chk(X) \
{document.location.href="BYOND://?src=\ref
[src]&chng="+X.name+\
"&val="+X.checked;}</SCRIPT></head>\
<body>
[message?"<div class=m>[message]</div>":""]\
<table align=center border=1 BORDERCOLORDARK=#808080 \
BORDERCOLORLIGHT=#404040 cellspacing=0 width=100%><tr>"}

/* style.css was made ahead of time and sent to all clients
at log in so they don't have to download that info
for every HTML page I transmit. */


// add the tabs
for(var/index in list("Appearance", \
"Base Stats", "AI Settings", "Effects & Items"))
if(page == index) // current page
html += "<td class=tab width=25%>[index]</td>"
else // any other page is clickable
html += {"\n<td class=h width=25% onClick=\
'document.location.href="BYOND://?src=\ref
[src]\
&page=
[url_encode(index)]";' \
onMouseOver='className="d"' \
onMouseOut='className="h"'>
[index]</th>"}

// end of the tabs section
html += "</tr><tr><td colspan=4 class=tab><table align=center \
width=100% border=1 BORDERCOLORDARK=#808080 \
BORDERCOLORLIGHT=#404040 cellspacing=0>"


// page content
switch(page)
if("Appearance")
html += PageAppearance()
if("Base Stats")
html += PageStats()
if("AI Settings")
html += PageAI()
if("Effects & Items")
html += PageEffects()
else
html += "<div align=center>Invalid page</div>"

// add common buttons and close everything up
html += {"</table></td></tr><tr><th colspan=4 align=center>\
<input type=button value='Save' onClick=\
'document.location.href="BYOND://?src=\ref
[src]\
&save";'> <input type=button value='Help!' onClick=\
'document.location.href="BYOND://?src=\ref
[src]\
&help=
[url_encode(page)]";'></th></tr></table></form>\
</body></html>"}


// show it to M
M << browse(html, "window=crit_[ID];size=600x400")
BigJMoney wrote:
This applies not only to input(), but also to html forms, etc. Basically, I want to know what some ideas are for going back and doing old things again in a proc. I've tried goto with strange results. while() seems like it might work, but be weird.

proc
askuser()
var/choice
do
. = input("Please enter the data.")
choice = alert("Continue with this data: [.]?",,"Yes","Back","Cancel")
if(choice == "Cancel") return null
while(choice == "Back")
return .


That's how I would probably set it up, using do ... while(). The while() shifts focus back to the do if it is true, which is the case when they press the Back button. I'd go with what Shadowdarke suggested for something larger or more complex.

~X
In response to YMIHere
Thanks once again for all the help, people. Another nice little thing out of this is that it finally hit me why one would use a do, while. I don't know, I guess I never took the time to look at them. :-/

It took me a while to get back to this; I posted it right before bed last night. I shall be posting my second question now. ;-)

=$=