ID:154060
 
I have two little programming puzzles that I'm not sure how to solve. And if I did solve them, they'd probably be pretty clunky solutions. Anyway, I'll post them here and if any of you out there know some proper ways to solve the problem, do feel free to share...

1. I want to setup a "Hit enter to Continue" button in the middle of a proc. So, you activate the proc, and the proc stops until you hit enter and continue the proc. What would be the ideal way to do this?

2. I want to cut out a specific chunk from a message and replace it with something else. The problem is that the chunk is not necessarily something specific, it's just highlighted by specific marks that can be searched for, such as: %blahblahblah%, where I'd want to capture whatever is inside the two %'s and replace it with something else. So, "You look at the %blah blah blah%." could become "You look at the toaster muffin." if I told it to replace whatever was within the %'s with "toaster muffin". I'm not sure what a decent way to do this would be. Ideas?
1. I want to setup a "Hit enter to Continue" button in the middle of a proc. So, you activate the proc, and the proc stops until you hit enter and continue the proc. What would be the ideal way to do this?

I would make the button just call a second proc.

2. I want to cut out a specific chunk from a message and replace it with something else. The problem is that the chunk is not necessarily something specific, it's just highlighted by specific marks that can be searched for, such as: %blahblahblah%, where I'd want to capture whatever is inside the two %'s and replace it with something else. So, "You look at the %blah blah blah%." could become "You look at the toaster muffin." if I told it to replace whatever was within the %'s with "toaster muffin". I'm not sure what a decent way to do this would be. Ideas?

Here's my solution (untested code). In it, you can't included nested % groups.

var/i = findtext(myText, "%")
if(i)
var/j = findtext(myText, "%", i)
myText = copytext(myText, 0, i) + "toaster muffin" + copytext(myText, j+1)

{Edit:] To replace different text depending on whats in the % groups, try this:

var/text_replace[] = list("blahblah"="toaster muffin", "blahblahblah"="cheese log", "flutz"="streudel", "foobar"="breakfast cereal")

while(1)
var/i = findtext(myText, "%")
if(i)
var/j = findtext(myText, "%", i)
myText = copytext(myText, 0, i) + text_replace[copytext(myText,i+1,j)] + copytext(myText, j+1)
else
break

[Edit 2:] Fixed the second one to perform any number of replacements.

-AbyssDragon
In response to AbyssDragon
For the first one, why not use either alert, or input(blah) as command_text.