Non-threaded

Forums » Advanced Editor Forum » Read Thread

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

Trying to use multiple variables with $PAGETEXT

7 years ago

Just when I think I'm getting the hang of scripting... I've got the player entering into a battle scenario, with the option to use one of two weapons. Each of the links is set up with scripting which determines if they hit the enemy, how much damage they do, if the enemy hits them, and how much damage the enemy does. The links just circle around to themselves until either the enemy is dead, or until the player is dead, or until the player chooses to retreat.

So, the problem I'm running into is this: I have a variable called %BATTLETRAC which keeps track of how many rounds of combat have passed. Each time the player clicks on a link, this variable increases by one. So, when I made the script for the page, this is what I did:

IF %BATTLETRAC = 1
THEN $PAGETEXT := "%%PLAYERRTH%<%12%You swing at the crocodile but your staff harmlessly bounces off its skull.%%%%PLAYERRTH%>=%12%Your staff connects, banging against the crocodile's skull with a satisfying thud. You've done some damage.%%" + "<br>" + "%%ENEMYRTH%<%ACHUNTER%The croc swings its mighty jaws toward you, but you're able to dodge out of the way.%%%%ENEMYRTH%>=%ACHUNTER%The croc's strong jaws close down on you! Ouch!%%" + "<br>" + "Your Health: %%PLAYERHP%%/%%HPHUNTER%%" + "<br>" + "Enemy Health: %%ENEMYHP%%/%%ENEMYMAXHP%%"
IF %BATTLETRAC = 2
THEN $PAGETEXT := "%%PLAYERRTH%<%12%Your quarterstaff harmlessly bounces off the croc's thick scales.%%%%PLAYERRTH%>=%12%You swing your quarterstaff directly into the crocodile's eyes! It blinks violently.%%" + "<br>" + "%%ENEMYRTH%<%ACHUNTER%The croc's jaws open and slam shut, but you manage to avoid being biten. This time.%%%%ENEMYRTH%>=%ACHUNTER%Your leg is caught in the croc's jaws! It shakes its head back and forth violently.%%" + "<br>" + "Your Health: %%PLAYERHP%%/%%HPHUNTER%%" + "<br>" + "Enemy Health: %%ENEMYHP%%/%%ENEMYMAXHP%%"
IF %BATTLETRAC = 3
THEN $PAGETEXT := "%%PLAYERRTH%<%12%You swing your staff down mightily toward the croc, but unfortunately your blow lands to the side of the croc's body.%%%%PLAYERRTH%>=%12%The staff lands directly on top of the croc's scaly head, seeming to stun it some!%%" + "<br>" + "%%ENEMYRTH%<%ACHUNTER%The crocodile thrashes back and forth, but you leap out of the way of its attack.%%%%ENEMYRTH%>=%ACHUNTER%The croc closes its jaws with a mighty bite directly onto your leg!%%" + "<br>" + "Your Health: %%PLAYERHP%%/%%HPHUNTER%%" + "<br>" + "Enemy Health: %%ENEMYHP%%/%%ENEMYMAXHP%%"

I was mostly trying to do this so there was some flavor and difference between each of the rounds. The %BATTLETRAC variable is working, but the variables for whether the player/enemy hits are displaying as typed, not as I intended for them to be scripted. Where have I gone wrong?

Trying to use multiple variables with $PAGETEXT

7 years ago
Because doing %%VARIABLE%% only works on the page itself. If you're putting it in the page script you can't use it that way.

Trying to use multiple variables with $PAGETEXT

7 years ago
Jah, that is an unfortunate truth.

Trying to use multiple variables with $PAGETEXT

7 years ago

So, the way around that is to have a single variable that tracks the round (%BATTLETRAC), whether the player hits (%PLAYERRTH >= %ENEMYAC), and whether the enemy hits (%ENEMYRTH >= %PLAYERAC)? And then script for each of those? Ie: 

IF %NEWVAR = 112 
THEN $PAGETEXT := "round one, hit for player, miss for enemy." 
IF %NEWVAR = 121 
THEN $PAGETEXT := "round one, miss for player, hit for enemy" 

Etc etc..

I'm not entirely sure how to script %NEWVAR into the link script, but maybe I can fiddle with that. 

Alternatively, are AND statements a thing? 

IF %BATTLETRAC = 1 AND %PLAYERRTH >= %ENEMYAC AND %ENEMYRTH >= %PLAYERAC 
THEN $PAGETEXT := "round one, hit for player, hit for enemy." 
IF %BATTLETRAC = 1 AND %PLAYERRTH < %ENEMYAC AND %ENEMYRTH >= %PLAYERAC 
THEN $PAGETEXT := "round one, miss for player, hit for enemy." 

Etc etc 

Which also seems complicated but probably easier than trying to figure out how to script for a new variable to track three other variables in the link script.

I feel like I'm making this hopelessly more complicated than I need to.

Trying to use multiple variables with $PAGETEXT

7 years ago

Like the others have said, that sort of coding won't work since it's parsed before page scripts are run. It's less compact, but the solution is to create a bunch of conditionals that all separately add on to the $PAGETEXT:

$PAGETEXT := ""

IF %BATTLETRAC = 1
THEN BEGIN
  
IF %PLAYERRTH < 12 THEN $PAGETEXT := $PAGETEXT + "You swing at the crocodile but your staff harmlessly bounces off its skull."
ELSE $PAGETEXT := $PAGETEXT + "Your staff connects, banging against the crocodile's skull with a satisfying thud. You've done some damage."

$PAGETEXT := $PAGETEXT + "<br>"

IF %ENEMYRTH < %ACHUNTER THEN $PAGETEXT := $PAGETEXT + "The croc swings its mighty jaws toward you, but you're able to dodge out of the way."
ELSE $PAGETEXT := $PAGETEXT + "The croc's strong jaws close down on you! Ouch!"

END

ELSE IF %BATTLETRAC = 2
THEN BEGIN

IF %PLAYERRTH < 12 THEN $PAGETEXT := $PAGETEXT + "Your quarterstaff harmlessly bounces off the croc's thick scales."
ELSE $PAGETEXT := $PAGETEXT + "You swing your quarterstaff directly into the crocodile's eyes! It blinks violently."

$PAGETEXT := $PAGETEXT + "<br>"

IF %ENEMYRTH < %ACHUNTER THEN $PAGETEXT := $PAGETEXT + "The croc's jaws open and slam shut, but you manage to avoid being biten. This time."
ELSE $PAGETEXT := $PAGETEXT + "Your leg is caught in the croc's jaws! It shakes its head back and forth violently."

END

ELSE BEGIN

IF %PLAYERRTH < 12 THEN $PAGETEXT := $PAGETEXT + "You swing your staff down mightily toward the croc, but unfortunately your blow lands to the side of the croc's body."
ELSE $PAGETEXT := $PAGETEXT + "The staff lands directly on top of the croc's scaly head, seeming to stun it some!"

$PAGETEXT := $PAGETEXT + "<br>"

IF %ENEMYRTH < %ACHUNTER THEN $PAGETEXT := $PAGETEXT + "The crocodile thrashes back and forth, but you leap out of the way of its attack."
ELSE $PAGETEXT := $PAGETEXT + "The croc closes its jaws with a mighty bite directly onto your leg!"

END

$PAGETEXT := $PAGETEXT + "<br>Your Health: " + %PLAYERHP + "/" + %HPHUNTER + "<br>Enemy Health: " + %ENEMYHP + "/" + %ENEMYMAXHP

Trying to use multiple variables with $PAGETEXT

7 years ago

Yes! Thank you so much! That's exactly what I was looking for!