I've got code that I am going to use a lot, all over the game. Right now I'm developing a copy&paste routine that I can use as the basis to all the storytelling. The problem is the coding section to check values is getting too big - I want a short routine to copy, not a page and a half.
Anyway, two lines of the 20-30 I've currently written look like this...
var FH = (100-((squiffy.get("fight_str"))*100)/6);
squiffy.set("fight percent",Math.floor(FH));
I'd like to subroutine these (and many other lines) to use as needed. So, how to make a subroutine to save me all this effort?
And here is my answer. While I'm only showing four lines of coding, there are several gains I get from learning this. In my actual application, there are something like 30 lines of java code that need to be run in many, many sections. Using the function call, I can recalculate these as needed. And, with the power of a subroutine like this, I can change it one place (and I don't have to laboriously copy it from section to section.
[[start]]:
squiffy.resolve("fight","run");
@set fight=-5
@set run=50
initial vals {fight} {run}
new vals {F} {R}
[[]]:
squiffy.resolve = function(fight,run) {
if (squiffy.get(fight)>10){squiffy.set("F",10);}
if (squiffy.get(fight)<0){squiffy.set("F",0);}
if (squiffy.get(run)>10){squiffy.set("R",10);}
if (squiffy.get(run)<0){squiffy.set("R",0);}
};