Non-threaded

Forums » Advanced Editor Forum » Read Thread

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

Interesting coding stuff

7 years ago

As Mizal said, it's definitely possibleI started writing this last night thinking it would be easy to script, then had to think about it for a while to come up with a shorter method (I only made the last bit shorter and couldn't figure out if the rest can be made shorter) and it turned out a lot bigger than expected. If you had to do this with 5 or 6 arcs, I don't even want to imagine how long it would take with my method. Then again, I've got a bad habit of writing some filthy code and there's probably a glaringly obvious simple solution that someone like Killa will bust out in a depressingly few number of lines. Still, here's my best shot:
First make an %ARCTOTAL variable (to track how many arcs have gone for randomisation) and %ARC1, %ARC2, %ARC3, and %ARC4 variables (to track which arcs you've gotten to so far). 


%VAR:= 1D4
IF %VAR = 1 THEN
%DEST:= @P
W
ELSE IF %VAR = 2 THEN $DEST:= @PX
ELSE IF %VAR = 3 THEN $DEST:= @PY
ELSE IF %VAR = 4 THEN $DEST:= @PZ
END

Where W, X, Y, and Z are the page numbers that start each arcs 1, 2, 3, and 4 respectively. You'll have to replace these yourself as I obviously don't know the page numbers seeing as they probably don't exist yet and it's your story. You'd need to rinse and repeat with 1D3 at the end of the first arc, and then with 1D2 after the second, then set up a link from the third to the fourth using the variables I's just about to mention. That's all below in a bit.

%ARCX:= 1 AND %ARCTOTAL:= %ARCTOTAL + 1 (I generally stay away from AND, but I think it can be used once in a line of code)

Where X is an arc number from one to four. You'd need to do this for each arc with the correct variable, changing only the X. This next long bit would go in the link script of the randomise link:

IF %ARCTOTAL= 1 THEN
BEGIN
%VAR:= 1D3
IF %ARC1 = 1 THEN
BEGIN
IF %VAR = 1 THEN
 $DEST:= @PX
ELSE IF %VAR = 2 THEN $DEST:= @PY
ELSE IF %VAR = 3 THEN $DEST:= @PZ
END
IF %ARC2 = 1 THEN 
BEGIN
IF %VAR = 1 THEN $DEST:= @P
W

ELSE IF %VAR = 2 THEN $DEST:= @PY
ELSE IF %VAR = 3 THEN $DEST:= @PZ
END
IF %ARC3 = 1 THEN 
BEGIN
IF %VAR = 1 THEN
 $DEST:= @PW
ELSE IF %VAR = 2 THEN $DEST:= @PX
ELSE IF %VAR = 3 THEN $DEST:= @PZ
END
IF %ARC1 = 4 THEN 
BEGIN
IF %VAR = 1 THEN
 $DEST:= @PW
ELSE IF %VAR = 2 THEN $DEST:= @PX
ELSE IF %VAR = 3 THEN $DEST:= @PY
END END

ELSE IF %ARCTOTAL = 2 THEN
BEGIN

%VAR:= 1D2
IF %ARC1 = 1 THEN
BEGIN
IF %ARC2=1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
Y
ELSE $DEST:= @PZ
END
ELSE IF %ARC3=1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
X 
ELSE $DEST:= @P
Z
END 
ELSE IF %ARC4 = 1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
X 
ELSE $DEST:= @P
Y

END END
ELSE IF 
%ARC2 = 1 THEN
BEGIN 
IF %ARC1 = 1 THEN
BEGIN

IF %VAR = 1 THEN $DEST:= @PY 
ELSE $DEST:= @P
Z
END
ELSE IF %ARC3=1 THEN 
BEGIN 
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @PZ

END
ELSE IF %ARC4=1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @P
X

END END
ELSE 
IF %ARC3 = 1 THEN
BEGIN 
IF %ARC1 = 1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
Y 
ELSE $DEST:= @PZ
END
ELSE IF %ARC2 = 1 THEN 
BEGIN 
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @P
Z
END
ELSE IF %ARC4=1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @PY

END END
ELSE 
IF %ARC4 = 1 THEN
BEGIN 
IF %ARC1 = 1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
X 
ELSE $DEST:= @PY
END
ELSE IF %ARC2=1 THEN 
BEGIN 
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @PY
END
ELSE IF %ARC3=1 THEN
BEGIN
IF %VAR = 1 THEN $DEST:= @P
W 
ELSE $DEST:= @P
X

END END END

ELSE IF %ARCTOTAL = 3 THEN
BEGIN

IF %ARC1 = 0 THEN $DEST:= @P
W
ELSE IF %ARC2 = 0 THEN $DEST:= @P
ELSE IF %ARC3 = 0 THEN $DEST:= @PY 
ELSE IF %ARC4 = 0 THEN $DEST:= @P

END

Ugh. Then copy and paste of all that into the link scripts of each arc ending in a link you want to lead to a randomised arc. Then, on pages where you want variable text, you can use these trackers to change text like this, for example:

'He turns to you and shouts, "%%ARCX%=%1%Don't underestimate me. I'm better than that Deadly Queen guy ever was and ever will be.%%%%ARCX%=%0%Don't underestimate me. Doing that means that the fight will be over that much sooner.%%"'

Personally, as long as you have a plot you're sticking to and the story is more than just four randomly generated events, I don't see why not. It'll take some work, but it adds some nice polish and replay value, and I like that kind of thing. If your text changes a lot based on whether a specific arc has come before the one the player is on, then you might want to set IF statements in the link scripts like this:

IF %ARCX = 1 THEN $DEST:= @PX
ELSE $DEST:= @PY

I hope this helps and good luck with your story!

Randomly ordered "scar"

7 years ago

You can save yourself some coding if you randomize the arcs at the beginning of the game, since there's no apparent difference. What I would do is start by initializing these variables:

%CURRENTARC: 0
%ARC1:       1
%ARC2:       2
%ARC3:       3
%ARC4:       4

Then, in the page script for the very first page (easiest if you make it a "title page"), shuffle the %ARC variables. I just cycle through every pair and with a 50% chance swap them; seems to produce decent results:

IF 1D2 = 1 THEN BEGIN %TEMP := %ARC1 %ARC1 := %ARC2 %ARC2 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC1 %ARC1 := %ARC3 %ARC3 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC1 %ARC1 := %ARC4 %ARC4 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC2 %ARC2 := %ARC1 %ARC1 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC2 %ARC2 := %ARC3 %ARC3 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC2 %ARC2 := %ARC4 %ARC4 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC3 %ARC3 := %ARC1 %ARC1 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC3 %ARC3 := %ARC2 %ARC2 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC3 %ARC3 := %ARC4 %ARC4 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC4 %ARC4 := %ARC1 %ARC1 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC4 %ARC4 := %ARC2 %ARC2 := %TEMP END
IF 1D2 = 1 THEN BEGIN %TEMP := %ARC4 %ARC4 := %ARC3 %ARC3 := %TEMP END

For any link that jumps to the next arc:

%CURRENTARC := %CURRENTARC + 1
IF %CURRENTARC = %ARC1 THEN $DEST := @PW
IF %CURRENTARC = %ARC2 THEN $DEST := @PX
IF %CURRENTARC = %ARC3 THEN $DEST := @PY
IF %CURRENTARC = %ARC4 THEN $DEST := @PZ

On-page coding for whether an arc has already occurred or not:

%%ARCX%<%CURRENTARC%This arc has already occurred.%%
%%ARCX%<=%CURRENTARC%This arc has already occurred or is the current arc.%%
%%ARCX%=%CURRENTARC%This arc is the current arc.%%
%%ARCX%>=%CURRENTARC%This arc has not occurred yet or is the current arc.%%
%%ARCX%>%CURRENTARC%This arc has not occurred yet.%%

Regular coding for whether an arc has already occurred or not:

IF %ARCX < %CURRENTARC THEN BEGIN
# This arc has already occurred
# Code goes here
END

Randomly ordered "CSAR" (Combat Search and Rescue)

7 years ago

I thought about scar too and sweet purple letters man. I bloody knew either you or Killa would trump me. Started writing my revolting code really late yesterday thinking 'This will be easy', and the horror kind of spiralled out of control as I got to the lengthier parts! I was wondering if there was a way to shuffle the arc variables, but couldn't think of a way to get close without having arcs with the same values; that's clever code to swap them around. 

I don't understand what the very last bit does and why it's useful. What's that about? 

Randomly ordered "царь" (eh)

7 years ago

Same thing as the first on-page coding I listed, but for a regular script. I just put comments in the block instead of making it actually do anything because there's more than one thing you could do with it—change $PAGETEXT in a page script, change $DEST in a link script like in your example, or something else even.

Interesting coding stuff

7 years ago
Glad this got rescued from the other thread. Can't make head or tails of it over the phone but it looks very effortful, thanks guys.