trying to get a small battle system going though seems we ran into a problem?
keep getting: 'SyntaxError: Unexpected identifier'
Currently its under test and everything is not set in stone so some things might be missing but here's what code we got so far...
[[Battle test]]:
@set testplayer_HP 100
@set testhostile_HP 0
@set testarmour_player 10
@set testarmour_hostile 0
@set testplayer_attack 5
@set testhostile_attack 0
@set testhostile_sheild 0
Battle test:
{label:0=[No Armour](battle 1) [Light](battle 2) [Heavy](battle 3).}
[battle 1]:
@replace 0= battle 1
@inc testhostile_hp 10
@inc testhostile_attack 2
found unarmours hostile
[[battle phase test]]
[battle 2]:
@replace 0= battle 2
found light armour hostile
[[battle phase test]]
[battle 3]:
@replace 0= battle 3
found heavy armour hostile
[[battle phase test]]
[[battle phase test]]:
Health: {testplayer_HP}HP
Armour rating: {testarmour_player}
Attack: {testplayer_attack}
[attack physical](test physical) [attack energy](test energy) [attack explosive](test explosive)
[test physical]:
does more damage to unarmoured
{if testhostile_sheild > 0:the attacks did minimal damage.{testhostile_sheild - (testplayer_attack * 0.2)}{testhostile_HP - (testplayer_attack * 0.2)}}
{else: {if testarmour_hostile > 0:the attack did some damage.}{testarmour_hostile - (testplayer_attack * 0.2)}{testhostile_HP - (testplayer_attack * 0.2)}}
{else: {if testhostile_HP > 0:the attack does decent damage.}{testhostile_HP - testplayer_attack}}
{else: unknown error}
Hostile stats...
Health: {testhostile_HP}
Armour: {testarmour_hostile}
sheild: {testhostile_sheild}
[test energy]:
does more damage to sheilds
{if testhostile_sheild > 0:the attacks did minimal damage.{testhostile_sheild - testplayer_attack}{testhostile_HP - (testplayer_attack * 0.2)}}
{else: {if testarmour_hostile > 0:the attack did some damage.}{testarmour_hostile - (testplayer_attack * 0.2)}{testhostile_HP - (testplayer_attack * 0.2)}}
{else: {if testhostile_HP > 0:the attack does decent damage.}{testhostile_HP - (testplayer_attack * 0.4)}}
{else: unknown error}
Hostile stats...
Health: {testhostile_HP}
Armour: {testarmour_hostile}
sheild: {testhostile_sheild}
[test explosive]:
does more damage to armour
{if testhostile_sheild > 0:the attack did some damage.{testhostile_sheild - (testplayer_attack * 0.2)}{testhostile_HP - (testplayer_attack * 0.4)}}
{else: {if testarmour_hostile > 0:the attack does decent damage.}{testarmour_hostile - testplayer_attack}{testhostile_HP - (testplayer_attack * 0.4)}}
{else: {if testhostile_HP > 0:the attacks did minimal damage.}{testhostile_HP - (testplayer_attack * 0.4)}}
{else: unknown error}
Hostile stats...
Health: {testhostile_HP}
Armour: {testarmour_hostile}
sheild: {testhostile_sheild}
{if testhostile_HP =< 0: [[Victory]](testvictory)}
{else: battle goes on [[end turn]](battle hostile test)}
[[battle hostile test]]:
{if testarmour_player > 0:the attack does some damage.{testarmour_player - testhostile_attack}{testplayer_HP - (testhostile_attack * 0.5)}}
{else: {if testplayer_HP > 0:the attacks does decent damage.{testplayer_HP - testhostile_attack}}
{else:unknown error}
Current status:
Health: {testplayer_HP}HP
Armour rating: {testarmour_player}
{if testplayer_HP =< 0: [[Victory]](testvictory)}
{else: battle goes on [[end turn]](battle hostile test)}
[[Defeat]]:
how?
[[testvictory]]:
well done
Idea is to have the player loop in the battle until someone reaches 0hp, then the game sends them back to where they were with a kind of checkpoint system or tell them that they died...
keep getting errors when using the {if}
and {else}
so we missing something?
If: There is a long-standing glitch, that I haven't isolated.
One workaround is to play with spacing around the colon. If you can use >= and <= instead of just > and <, do so. Another is to force Squiffy to read glitchy numbers as numbers:
@dec testplayer_HP 1
@inc testplayer_HP 1
else: This is not js elseif! It only looks for the last if statement regardless of nesting. It is not useful for clever logic.
I'm not competent in JavaScript, but I use copypasta when Squiffy glitches.
so what can we use instead of the else:
if it doesn't work?
seems no matter what, it comes up with an error, even taking away the else:
so either it hates trying to figure out calculations like (price * amount)
(aka: price x amount) or it hates everything under 0 like, 0.1, 0.2 etc.
Edit: found a solution... sort of,
seems the software hates anything with finding something from the 'player' in the viable, know this because we did a line each and after inputting last few lines with 'player' in the varible, it comes up with the 'SyntaxError: Unexpected identifier' Error...
No idea why this does this but seem to be the reason for this whole thing not to work... any able to see reason why it doesn't work?
A Squiffy section or passage is divided into three parts, which use different types of code.
The first part is Javascript, which is a full scripting language. The javascript part goes from the start of the section (or passage) to the first line that doesn't start with four spaces.
So this piece is your problem:
[[battle hostile test]]:
{if testarmour_player > 0:the attack does some damage.{testarmour_player - testhostile_attack}{testplayer_HP - (testhostile_attack * 0.5)}}
{else: {if testplayer_HP > 0:the attacks does decent damage.{testplayer_HP - testhostile_attack}}
{else:unknown error}
Those lines start with 4 spaces, and are not javascript.
If you want them to be parsed through Squiffy's text processor, you need to either remove the spaces or put something else before them.
Also, I'm a little puzzled by the code there. I can't find anything in the Squiffy source that lets it do maths like that. If I'm understanding what you're trying to do correctly, you might need to make it something like:
[[battle hostile test]]:
{if testarmour_player > 0:the attack does some damage.{@testarmour_player -= @testhostile_attack,temp_attack_damage=@testhostile_attack,temp_attack_damage*=0.5,testplayer_HP -= @temp_attack_damage}}
{else: {if testplayer_HP > 0:the attacks does decent damage.{testplayer_HP -= @testhostile_attack}
{else:unknown error}}
or you could use javascript, which is usually a better option for more complex situations:
[[battle hostile test]]:
var player_armour = squiffy.get("testarmour_player");
var player_HP = squiffy.get("testplayer_HP");
var hostile_attack = squiffy.get("testhostile_attack");
if (player_armour > 0) {
squiffy.set("temp_message", "the attack does some damage");
player_armour -= hostile_attack;
player_HP -= hostile_attack * 0.5;
} else if (testplayer_HP > 0) {
squiffy.set("temp_message", "the attack does decent damage");
player_HP -= hostile_attack;
} else {
squiffy.set("temp_message", "Unexpected error: player_HP is 0 or less");
}
squiffy.set("testarmour_player", player_armour);
squiffy.set("testplayer_HP", player_HP);
{temp_message}.
(Setting the attribute temp_message
so that you can include a message from the JS in the body text of the section. An alternative would be to use squiffy.ui.write("Some message");
- as long as you don't mind your JS output being before the main part of the text.
tried other ways like this:
[[Battle test]]:
@clear
@set testplayer_HP 100
@set testhostile_HP 1
@set testarmour_player 10
@set testarmour_hostile 1
@set testplayer_attack 5
@set testhostile_attack 1
@set testhostile_sheild 1
Battle test:
{label:0=[No Armour](battle 1) [Light](battle 2) [Heavy](battle 3).}
[battle 1]:
@replace 0= battle 1
@inc testhostile_hp 10
@inc testhostile_attack 2
found unarmours hostile
Fight:
[[battle phase test]]
[battle 2]:
@replace 0= battle 2
found light armour hostile
Fight:
[[battle phase test]]
[battle 3]:
@replace 0= battle 3
found heavy armour hostile
Fight:
[[battle phase test]]
[[battle phase test]]:
Status:
Health: {testplayer_HP}HP
Armour rating: {testarmour_player}
Attack: {testplayer_attack}
{label:00=[attack physical](test physical attack) (does more damage to unarmoured)}
{label:00=[attack energy](test energy attack) (does more damage to sheilds)}
{label:00=[attack explosive](test explosive attack) (does more damage to armour)}
[test physical attack]:
@replace 00=
attack
{if testhostile_sheild=>1:{ squiffy.story.passage("testsheild physical hit")} }{else: }
{if testarmour_hostile=>1:{ squiffy.story.passage("testarmour physical hit") }{else: }
{if testhostile_HP=>1:{ squiffy.story.passage("testhealth physical hit")} }{else: }
{if testhostile_HP=<0:[[testvictory]].}{else: error }
[testsheild physical hit]:
@inc testhostile_hp {testplayer_attack * 0.2}
squiffy.story.passage("Hostile stats")
[testarmour physical hit]:
@inc testhostile_hp {testplayer_attack * 0.8}
squiffy.story.passage("Hostile stats")
[testhealth physical hit]:
squiffy.story.passage("Hostile stats")
@inc testhostile_hp {testplayer_attack * 1.2}
[test energy attack]:
@replace 00=
[test explosive attack]:
@replace 00=
[Hostile stats]:
Hostile status:
Health: {testhostile_HP}
Armour: {testarmour_hostile}
sheild: {testhostile_sheild}
[battle hostile test]:
[[testDefeat]]:
how?
[[testvictory]]:
well done
but no matter what nothing happens, this software just refused to combine commands or calculate things together....
If someone finds a way to do it then cool... am giving up on a battle system using this thing lol
tried other ways like this:
Did you check out my post earlier?
but no matter what nothing happens, this software just refused to combine commands or calculate things together....
There are three parts to a Squiffy section or passage. They MUST come in the right order.
FIRST The javascript part - lines starting with 4 spaces
SECOND The assignments part - lines start with a @ sign
THIRD The text part - Text that's displayed to the player, and text processor commands inside {
and }
You have:
{if testhostile_sheild=>1:{ squiffy.story.passage("testsheild physical hit")} }{else: }
{if
is a text processor command, and can only go in the third part. squiffy.story.passage
is a javascript function, and can only go in the first part.
If you want to do this, you need to put it in the javascript part, and use a javascript if
statement instead of the text processor one.
A text processor if statement looks like:
{if condition: Text to display if it's true}
The javascript version is:
if (condition) {
Javascript commands to run if it's true
}
They do similar things, but if you want to use squiffy.story.go
or similar you need to use the javascript one.
So the statement I just quoted should be:
if (squiffy.get("testhostile_sheild") >= 1) {
squiffy.story.passage("testsheild physical hit");
}
(note – you get Squiffy attributes in javascript you use squiffy.get
. Also, the greater-than-or-equal-to operator is >=
, not =>
(which is the non-closing lambda operator))
Also, you have lines like:
@inc testhostile_hp {testplayer_attack * 0.2}
I'm pretty sure this won't work. It tries to add 1 to an attribute named testhostile_hp {testplayer_attack * 0.2}
.
You can't use {}
expressions in the assignments part, only in the text processor part. And the value being added needs to be either a number or another attribute.
If you want to do calculations like this in the text processor, you can use a temporary variable. Like this:
{@damage_done = @testplayer_attack} <= this sets one attribute to be equal to the other
{@damage_done *= 0.2} <= this multiplies the temporary variable by 0.2
{@testhostile_hp -= @damage_done} <= this reduces testhostile_hp by the temporary variable
I'm not sure if you can do the same thing with @set
in the attributes part - it's likely, but I've never tried it
Or you could do it in the Javascript part:
var hp = squiffy.get("testhostile_hp"); // gets a Squiffy attribute into a JS variable
var damage = squiffy.get("testplayer_attack");
hp -= damage * 0.2; // JS lets you use expressions on the right had side of an =
squiffy.set("testhostile_hp", hp); // and put the result back in a Squiffy variable
or without all the temporary variables that would be:
squiffy.set("testhostile_hp", squiffy.get("testhostile_hp") - squiffy.get("testplayer_attack") * 0.2);
(which is shorter, but maybe harder to understand)
Basically, try to use the different commands in the part that they work in.
Does that help?
The "RUN" button is your friend. While I'm coding JS, I hit it every line or two to make sure I can still compile. If you sit all night and code, you'll find yourself behind the eightball if something goes wrong.