Non-threaded

Forums » Advanced Editor Forum » Read Thread

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

Else if statements

11 years ago
I need a script to put on a single link with a variable that allows it to go to one of six pages.

I tried IF ELSE IF statements, but they don't seem to work...am I doing something wrong or do I need to split it up into multiple scripts? Does the script not activate in order of IF ELSE? I'm probably doing something wrong with my less-than symbols.

%CHANCE := 1D100

IF %CHANCE > 20 THEN

$DEST := @P2

ELSE

IF %CHANCE > 40

$DEST := @P3

ELSE

IF %CHANCE > 60

$DEST := @P4

ELSE

IF %CHANCE > 80

$DEST := @P5

ELSE

IF %CHANCE > 100

$DEST := @P6

Else if statements

11 years ago

Perhaps you need BEGIN and END statements. Also, you have no less than symbols. Also, that script will never send you to p6.

Else if statements

11 years ago
It worked without them before so I assumed they weren't always needed, where would I put them within this script to have it work?

Else if statements

11 years ago

Why are your else and if statements on different lines? That may be screwing up the script.

You say it doesn't seem to work, but what is actually happening?

Else if statements

11 years ago
I'm still new to scripting, and I'm learning stuff through experimentation. I figured it would work like JavaScript but it doesn't - so I've just been winging it most of the time. I want a single link to have an equal chance to go to one of five pages, and I don't know what script to use for that. The else and if statements are on different lines because I'm using this thread as a reference.

Else if statements

11 years ago

So.. what happens when you run it? It's easier to debug a problem when we know what happens after you run it.

%CHANCE := 1D100

IF %CHANCE > 0 AND %CHANCE <= 20 THEN
BEGIN
$DEST = @P1
END

IF %CHANCE > 20 AND %CHANCE <= 40 THEN
BEGIN
$DEST = @P2
END

IF %CHANCE > 40 AND %CHANCE <= 60 THEN
BEGIN
$DEST = @P3
END

IF %CHANCE > 60 AND %CHANCE <= 80 THEN
BEGIN
$DEST = @P4
END

IF %CHANCE > 80 AND %CHANCE <= 100 THEN
BEGIN
$DEST = @P5
END

Is what I'd use. I'm not 100% sure that AND operators work in CYS scripting, but I think they do.

Else if statements

11 years ago
It doesn't run at all - it cannot save the script due to errors. If it did run the script, I'd have no problems. I'd figure it out myself, but the script doesn't save in the first place because it's invalid and has errors.

That script doesn't save either due to errors.

Else if statements

11 years ago

Which line/column does it bug out at?
 

Else if statements

11 years ago

Else if statements

11 years ago

Weird. Try clicking validate instead of save.
 

Also, do either of these work:

-----------------------------

%CHANCE := 1D100

IF %CHANCE > 0 AND %CHANCE <= 20 THEN $DEST := @P1
IF %CHANCE > 20 AND %CHANCE <= 40 THEN $DEST := @P2
iF %CHANCE > 40 AND %CHANCE <= 60 THEN $DEST := @P3
IF %CHANCE > 60 AND %CHANCE <= 80 THEN $DEST := @P4
IF %CHANCE > 80 AND %CHANCE <= 100 THEN $DEST := @P5
 

-------------------

%CHANCE := 1D100

IF %CHANCE > 0 AND IF %CHANCE <= 20 THEN $DEST := @P1
IF %CHANCE > 20 AND IF %CHANCE <= 40 THEN $DEST := @P2
iF %CHANCE > 40 AND IF %CHANCE <= 60 THEN $DEST := @P3
IF %CHANCE > 60 AND IF %CHANCE <= 80 THEN $DEST := @P4
IF %CHANCE > 80 AND IF %CHANCE <= 100 THEN $DEST := @P5

Else if statements

11 years ago
Did not expect '=' on line 5 column 8

Else if statements

11 years ago

OH! Haha, change = to := for the DEST lines.

%CHANCE := 1D100

IF %CHANCE > 0 AND %CHANCE <= 20 THEN
BEGIN
$DEST := @P1
END

IF %CHANCE > 20 AND %CHANCE <= 40 THEN
BEGIN
$DEST := @P2
END

IF %CHANCE > 40 AND %CHANCE <= 60 THEN
BEGIN
$DEST := @P3
END

IF %CHANCE > 60 AND %CHANCE <= 80 THEN
BEGIN
$DEST := @P4
END

IF %CHANCE > 80 AND %CHANCE <= 100 THEN
BEGIN
$DEST := @P5
END

Else if statements

11 years ago
Worked! Hooray! xD

Well, it saved as a valid script - but now when I try it, it only takes me to page 2. Even after multiple tries, either I'm really unlucky and got page 2 several times in a row, or the script doesn't work... *continues trying script in-game*

Seems to only take me to page 2 and not any other page :(

http://chooseyourstory.com/story/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz - the game I made for testing the script.

Else if statements

11 years ago

give me 5 minutes

@Ford

It works now. Check it out. (Unless you've changed it since I fixed it). And statemetns were the problem.

Else if statements

11 years ago
First one: did not expect = on line 3 column 45

second one: did not expect IF on line 3 column 20

Edit:: Ah I see. Let me try that :D

Else if statements

11 years ago

...

Just do:

%CHANCE := 1D6

IF %CHANCE = 1 THEN

BEGIN

$DEST := @P1

END

IF %CHANCE = 2 THEN

BEGIN

$DEST := @P2

END

IF %CHANCE = 3 THEN

BEGIN

$DEST := @P3

END

IF %CHANCE = 4 THEN

BEGIN

$DEST := @P4

END

IF %CHANCE = 5 THEN

BEGIN

$DEST := @P5

END

IF %CHANCE = 6 THEN

BEGIN

$DEST := @P6

END

Else if statements

11 years ago

That's an elegant solution, too, but sometimes you want to modify the number without guaranteeing a change in value. For instance, the character might have a 'lucky' trait that increases the %CHANCE by 10, which is likely but not guaranteed to improve the result.

Else if statements

11 years ago

The best solutions are sometimes the easiest solutions. The thing with scripting is, the less complicated you make it, the easier you make it on yourself in the long run. I mean, setting chance to 100 was totally unnecessary, and then setting the if statements to > and < was even more unnecessary.    

Else if statements

11 years ago

Setting chance to 100 is only unnecessary if you don't plan to ever have character modifiers on the roll.

Else if statements

11 years ago

Can you give me an actual example of what you mean? I don't quite understand what you're trying to say.

Example: If you want so and so, then you increase the so and so, and it won't work that way, because so and so.

Else if statements

11 years ago

See below.
 

Else if statements

11 years ago

Hold on. You mean like you want to make it to land on a certain page, and by increasing chance, you increase the likelihood of landing on that page?

Else if statements

11 years ago

Let's say that, for example, there are three outcomes:

Outcome 1: Character death (p3)
Outcome 2: Character injury (p4)
Outcome 3: No character injury (p5)

Let's say that the situation is that you need to dodge a sword, let's say the character has a dexterity stat between 1-20.

%CHANCE := 1D100 + %DEXTERITY

Then,

IF %CHANCE > 30 THEN $DEST = @P3
IF %CHANCE > 60 THEN $DEST = @P4
IF %CHANCE > 90 THEN $DEST = @P5

Using a 1-100 system gives you more flexibility.

Else if statements

11 years ago

Well, I see what you mean now. Yes, if you're doing percentage, and is using a separate variable to increase the likelihood of that percentage roll, then using chance as 100, is 100% necessary, but if you're just doing random destinations, then using the simpler solution would be better. 

Else if statements

11 years ago

I wouldn't say that it's better, honestly. I guess it's better if you don't understand math very well. There's really no reason why this

%CHANCE := 1D100

IF %CHANCE > 0 THEN $DEST = @P3
IF %CHANCE > 25 THEN $DEST = @P4
IF %CHANCE > 50 THEN $DEST = @P5
IF %CHANCE > 75 THEN $DEST = @P6

is worse than this:

%CHANCE := 1D4

IF %CHANCE = 1 THEN $DEST = @P3
IF %CHANCE = 2 THEN $DEST = @P4
IF %CHANCE = 3 THEN $DEST = @P5
IF %CHANCE = 4 THEN $DEST = @P6

Else if statements

11 years ago

The reason is that you make it easier on yourself. Sometimes, when you are scripting multiple pages and pages of scripts, one easy mistake can bring the whole script down. Not only does using simpler solutions whenever you can, makes it easier on yourself, but when something goes wrong, it's also easier to go through your scripts, and find out what the problems are, faster. 

Else if statements

11 years ago

I don't think that either of those scripts are complicated, at all. This isn't like a programming project with 50 interconnected modules. If there's a problem, you can immediately pinpoint which page it is, and neither of the above scripts are hard to deciper.

Else if statements

11 years ago

You're right. Neither of those scripts are complicated, but one of them is most definitely more complex than the other one. Using more complex scripts when it's unnecessary, slows you down, if even a little, and when you're scripting, you want to get things done, as fast as you can, so there's no point in using a more complex scripting over a more simpler scripting when both works equally as good, unless you want to challenge yourself.  

Else if statements

11 years ago

Like 10 variables opposed to 36? Haha.

Else if statements

11 years ago

Yes, I'm still ashamed that you thought of it, when I didn't. xD 

Else if statements

11 years ago

I don't know whether that's a compliment or an insult. Haha.

Else if statements

11 years ago

It's a compliment, of course. I've been scripting for months, and you just started. I'm ashamed that a newbie thought of a simpler solution, when I couldn't. 

Else if statements

11 years ago

Okay. I still need to work on it, though. My scripting, I mean, not that particular thing. I am trying to build a pretty neat combat system in one of my games with all sorts of spells that you can unlock throughout the game. The only problem is all the scripting it requires.

Else if statements

11 years ago

Ha. You're not kidding. Don't be surprise if it takes you months to actually complete it. It really does take that long. 

Else if statements

11 years ago

Yeah, it took me two days to set up the scripting necessary to give the player the option of choosing their character name...and fit it on a single page. I did it in a way similar to how I did the keycode thing, and I was able to do it on one page with 27 links (1 for each letter, and 1 "Continue" link.) And, yes, it does work.

Else if statements

11 years ago

I think you might actually be a scripting genius. It takes most people way longer than a few days to get familiar with scripting, and to come up with working algorithms.  

Else if statements

11 years ago

Well, actually, I'm just teaching myself a few simple tricks and using them extensively. I still haven't gotten into the complex $DEST stuff like you and 3J are discussing.

Else if statements

11 years ago

It's truly not complicated. I would argue that there is no such thing as a complicated CYS script element.

Else if statements

11 years ago

I just mean that It appears more intimidating to me than anything I have messed with thus far. The BEGIN & END thing throws me off. I've only used $DEST when making a little key code thing.

Else if statements

11 years ago

Complex? Not at all. $DEST just sets the page number you want the link to go to. There are a few ways to use it, but I think you just need to know 2 for now. 

The first way is setting the link to any page you want it to go to:

$DEST := @P100

The above says set the destination to at page 100.

The second way is setting the link to stay at the same page:

$DEST := @NONE

The above says set the destination to none, which means set it to stay at the same page. 

Else if statements

11 years ago

That pretty much covers it. Alternatively, you can set $DEST := @X where X is the current page ID to accomplish the same thing.

Else if statements

11 years ago

Oh, that might help me later on. So, like this? 

IF %MONSTHP > 0 THEN

  BEGIN

  $DEST:= @NONE

  END

IF %MONSTHP = 0 THEN

  BEGIN

  $DEST := @P32

  END

Else if statements

11 years ago

That script would work.

Else if statements

11 years ago

Ah, good.

Else if statements

11 years ago

Yes, that works perfectly. 

Else if statements

11 years ago

On the other hand, using a D100 script allows you to easily go back and add a modifier, without having to modify the whole script.

Else if statements

11 years ago

Agree. So the question really comes down to whether the scripter wants to prepare for every eventual scripts he'll need down the line, or just scripts for what he needs as of now. 

Else if statements

11 years ago

That's a pretty common question that programmers ask all of the time. It's all personal preference.

Else if statements

11 years ago
Zark you and your simple solutions that make me look stupid xD

Else if statements

11 years ago

Before you change it, look at the script that I've put in there, in your test storygame. It's working, currently.

Else if statements

11 years ago
Great! It certainly works but there's no way for me to see the script unless it's one of the scripts in the thread xD

Else if statements

11 years ago

You should be able to see it. Go into the pages list and go to the page and open up the link script?

This is the script, though:

%CHANCE := 1D100

IF %CHANCE > 0 THEN
 BEGIN
 $DEST := @P2
 END

 IF %CHANCE > 20 THEN
 BEGIN
 $DEST := @P3
 END

IF %CHANCE > 40 THEN
 BEGIN
 $DEST := @P4
 END

IF %CHANCE > 60 THEN
 BEGIN
 $DEST := @P5
 END

IF %CHANCE > 80 THEN
 BEGIN
 $DEST := @P6
 END

Else if statements

11 years ago
Nope, don't see anything - but I know it's there because it's working.

Else if statements

11 years ago

Um. This > means greater, not less. 

Else if statements

11 years ago
? :3 I know...

Else if statements

11 years ago

I definitely don't believe you. ;)

Else if statements

11 years ago

The power of editing...;O

Else if statements

11 years ago

Actually, you only need BEGIN/END Statements when you want the IF Statement to perform more than 1 Operation.

So this (Stolen from JJJ) would work fine.

%CHANCE := 1D100
IF %CHANCE > 0 THEN $DEST := @P2
IF %CHANCE > 20 THEN $DEST := @P3
IF %CHANCE > 40 THEN $DEST := @P4
IF %CHANCE > 60 THEN $DEST := @P5
IF %CHANCE > 80 THEN $DEST := @P6

Also not that the system only redirrects your page to the last true statement, so, if you entered the above like this -

%CHANCE := 1D100
IF %CHANCE > 80 THEN $DEST := @P6
IF %CHANCE > 60 THEN $DEST := @P5
IF %CHANCE > 40 THEN $DEST := @P4
IF %CHANCE > 20 THEN $DEST := @P3
IF %CHANCE > 0 THEN $DEST := @P2

It would always go to page 2 (no matter what the result of %CHANCE was).

Else if statements

11 years ago

He meant <, not >.

Else if statements

11 years ago

No, Berka knows that. She's just explaining what would happen if you don't use begin and end statements, consistently. 

Else if statements

11 years ago

When did Berka get a sex change?

Else if statements

11 years ago

What? Berka was always a she to me. She's a male? 

Else if statements

11 years ago

He must have caught me in drag...

Else if statements

11 years ago

No. The penguin with the hammer looks suspiciously female. 

Else if statements

11 years ago

That's Ringo from Madagascar. He's so manly that he's incapable of speech.

Else if statements

11 years ago

Yeah. That's what happens when you use an animal as a profile picture. People gets confuse of their sex. 

Else if statements

11 years ago

But, Berka is a guy. In Dead Man Walking, Berka makes a reference to his Lady Zerka...and in an older thread, he said he was slightly opposed to gay marriage, so I think the only option is that Berka is a male.

Else if statements

11 years ago

Well, to be fair, females can fall in love with other females too, and they can also be oppose to gay marriage. 

Else if statements

11 years ago

Oh, sorry. I guess the options are:

1. Berka is a male.

2. Berka is a lesbian who doesn't believe that gay marriage is a big deal or believes that marriage, in general, is overrated.

Granted, the second is possible. I still don't think that a lesbian would refer to her lover as lady, though.

Else if statements

11 years ago

What then, do you think lesbians refer to their lovers as? 

Else if statements

11 years ago

Other affectionate titles. To call the other lady would have the implication that the other is not, in fact, a lady...or that the title was not meant in an affectionate way.

Else if statements

11 years ago

In that case, he'd actually want reverse order of above -

%CHANCE := 1D100
IF %CHANCE < 100 THEN $DEST := @P6
IF %CHANCE < 80 THEN $DEST := @P5
IF %CHANCE < 60 THEN $DEST := @P4
IF %CHANCE < 40 THEN $DEST := @P3
IF %CHANCE < 20 THEN $DEST := @P2