Non-threaded

Forums » Advanced Editor Forum » Read Thread

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

Scripting Or Variable?

12 years ago

Okay, I don't know wether this is a Scpt. or V. question. It's been a long time since I've actually tried working on anything, so I basically forgot everything :P. My scenario is this:

Let's say you are Robin Hood. You are currently staking out enemy caravans and shooting them down. I want it so that when you slick the Shoot Arrow link, that it will give a random option of three. The options are either miss, hit, or get attacked and miss.

If my explanation is confusing, take it like dice. With three sides...

(This also works with the end area, if you hit the caravan. I want it to give a random amount of money to you. I don't know what I'm doing... 

P.S: I'm sorry if I'm useless when it comes to examples and information)

Scripting Or Variable?

12 years ago

This help article describes random variables http://chooseyourstory.com/help/articles/article.aspx?ArticleId=14

If you make a variable called shoot you can have your script look like this:

 

%SHOOT:= 1D3
IF %SHOOT = 1 THEN
code for when the arrow hits the target
IF %SHOOT=2 THEN
BEGIN
code for when you miss
END
IF %SHOOT=3 THEN
BEGIN
code for when you get attacked
END
 
I have a similar scenario with throwing something in my unfinished story.

Scripting Or Variable?

12 years ago

When in doubt, the answer is always both.

And in this case the answer really is both.

In the "Shoot Arrow" link's script is where you you do that logic. You can change the destination page of the link dynamically using scripting. So in the link script you'd do something link:

%SHOOT:= 1D3
IF %SHOOT = 1 THEN
$DEST := @65
ELSE IF %SHOOT=2 THEN
$DEST := @66
ELSE IF %SHOOT=3 THEN
$DEST := @67
 
Every page has an id number, which is what $DEST is referring to. So you'd have a hit page, and a miss page, and a get attacked and miss page.

Scripting Or Variable?

12 years ago

Okay, I'm starting to catch on a bit. But would this also give a random amount of damage given (In the case that the player is attacked)? Pr will there be a certain amouint of HP taken away?

Scripting Or Variable?

12 years ago

It could be used for that, but all the code I showed above did was make a random number between 1 and 3, then depending on a number go to a different page. I mean you could add more stuff to do that, for example:

%SHOOT:= 1D3
IF %SHOOT = 1 THEN
$DEST := @65
ELSE IF %SHOOT=2 THEN
$DEST := @66
ELSE IF %SHOOT=3 THEN
BEGIN
%DAMAGE := 1D8
IF %DAMAGE - %HEALTH > 0 THEN
BEGIN
$DEST := @67
%HEALTH := %HEALTH - %DAMAGE
END
ELSE
BEGIN
$DEST := @68
END
END
 
So, once we have established the player is attacked (If %SHOOT = 3), then we decide how much damage is done, which is between 1 and 8 damage (Green part). If the damage done is less than their health left (pink part) then they go to a page where they're still alive but injured. Otherwise, if the damage done is more or equal to their health, they go to a death page (red).
 
You should read a bit more into scripting to find out what you can and cannot do. Just go to "Help and Info" and start reading the articles involving scripting.

Scripting Or Variable?

12 years ago

Okay, I get it a bit more. Thanks, I'll take another look at the Scripting page. Thanks!