Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Word substitution through a script?

13 years ago

I haven't found anything in the forums dealing with this yet. What I'm discussing here is the ability to conduct pre-processing of storygame pages before they are displayed to the reader. The goal being that certain strings within the page would be replaced by other strings specified in a global script. Here's a hypothetical example:

I have 3 characters in my story that may possibly accompany the protagonist, let's name them Tom, Dick, and Harry. During the scenes that have them, they're going to say and do the same things, only the name will change. Their name will be used within the text, not at the beginning or end, so this won't work:

 

$PAGETEXT := $PAGETEXT + " Dude's name is Dick."

 

is there a way to search through the $PAGETEXT variable and replace a code, to prevent overlap to other story elements, I'd use something like "0AP34GHTXP" where the names would be. I'd imaging the code to look something like:

 

IF $FRIEND = 1 THEN

REPLACE "0AP34GHTXP" WITH "Tom" IN $PAGETEXT

ELSE IF $FRIEND = 2 THEN

REPLACE "0AP34GHTXP" WITH "Dick" IN $PAGETEXT

ELSE

REPLACE "0AP34GHTXP" WITH "Harry" IN $PAGETEXT

 

Any thoughts? Has this been discussed and I missed it?

I've been through all the tutorials that related to scripting and didn't find anything about this in specific, but it seems like the kind of feature that would have at least been thought about by someone.

Word substitution through a script?

13 years ago

This may be an alterior way to do what you want:

%%VARIABLE%=%1%"This text only appears if VARIABLE = 1"%%

As such, you can type:

Dude's name is %%FRIEND%=%1%Tom%%%%FRIEND%=%2%Dick%%%%FRIEND%=%3%Harry%%.

Through this, the text shows Tom if FRIEND=1, Dick if FRIEND=2 and Harry if FRIEND=3.

Word substitution through a script?

13 years ago

Alright, just to make sure I understand the usage that you're describing:

This would be inserted into the page itself (among the text that will be displayed when the reader arrives at the page) and the syntax is

% - to open

%[variable name]%=%[variable value]%[string to be inserted]%

% - to close

in english it would be "if [variable name] is [variable value] then print [string to be inserted] here"?

 

This is exactly the functionality I was looking for, a little cumbersome to use but much more flexible than the method I had in mind. Thanks!

Word substitution through a script?

13 years ago
Sorry, there's no replace function as is but that's an interesting idea. I think SindriV hit on the only way to do it. This belongs in the Advanced Editor forum btw, definitely not a newbie question! :) You have the syntax right, but remember than the logical operator can be =, < or >. (So 'is' can be replaced by 'is greater than' or 'is lesser than'.)

Word substitution through a script?

13 years ago

Excellent information about the operator! Thanks guys!

Word substitution through a script?

13 years ago
You can also use scripting to do something like this

IF %VARIABLE = 1 THEN
$PAGETEXT := "bla bla bla bla bla NAMEX bla bla bla NAMEX bla"
ELSE
$PAGETEXT := "bla bla bla bla bla NAMEY bla bla bla NAMEY bla"

Pretty sure I got the syntax wrong since I haven't scripted in forever, but you get the picture. You can assign the whole page text instead of doing $PAGETEXT := $PAGETEXT + etc.

Word substitution through a script?

13 years ago

Alright, let's ratchet up the complexity a notch. I have a page that has a few paragraphs on it, and (based on variables)there might be another paragraph inserted. I've tried inserting HTML to create page breaks, but the engine dutifully just diplays the html tags like regular text. Here's an illustration of the issue:

 

Paragraph 1.

Paragraph 2.

[This is where the variable dependent paragraph would be if its displayed. If not, I don't want empty whitespace here]

Paragraph 3.

 

So far, the methods I've tested either resulted in extra whitespace, or no seperation between the inserted paragraph and the one below is (or as I mentioned above, HTML tags plainly visible in the middle of my text).

Any advice on this one?

Word substitution through a script?

13 years ago

So you want paragraph 3 to be visible no matter what?

Alright, basically, what you should to is:

Paragraph 1.

Paragraph 2.

%%VARIABLE%=%1%The extra paragraph depending on the variable.%%%%VARIABLE%=%0%Paragraph 3.%%

%%VARIABLE%=%1%Paragraph 3%%

 

Word substitution through a script?

13 years ago

Your solutions continue to be as elegent as they are simple!  Thank you yet again!

And I still can't figure out why that didn't occur to me, I was trying some really kooky stuff to get the same result; and failing miserably. 

The answers beget their own questions...

13 years ago

Alright, this thread was very enlightening. As I've been writing I've continually been able to find the things I need with the help files. While there is a ton of good info on scripting and the engine itself, I'm not finding anywhere that details the things you can sneak into the page itself, like the %%[stuff]%% method listed above.

Any advice on where to look? Or if there isn't a help file on it, is there at least a quick and dirty list someone (you..) can throw up with whatever options you have personally found useful?

 

Also, I've been reading other stories and decided to include images in mine. How do you get them to appear in the upper right (as seems to be the accepted use) of a page. Again, if you could just point me to where the info is, I'd be grateful.

The answers beget their own questions...

13 years ago
http://www.myadventuregame.com/help/articles/article.aspx?ArticleId=80

This article by October should tell you what you need to know.

The answers beget their own questions...

13 years ago

I'll check it out when I get home. What's funny is my workplace blocks "www.myadventuregame.com" but not "chooseyourstory.com", LOL!

Thanks!

The answers beget their own questions...

13 years ago

alright, I just changed the root location and it worked. Silly webpage blocker.