Scenario start_state problems

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Scenario start_state problems
Master
Member # 5977
Profile Homepage #0
I'm currently busy updating WtRM to versionb 2.0.0, but I have stumbled upon a large, worrying problem: It seems the start_state of the scenario script is only run once, while other states, after they have been triggered by the start_state, run constantly. Is there something in the following bit of code, copied out from the start_state, that could cause this behavior?

beginstate START_STATE;

// [string]

a = 1;
print_num(a);

if (get_flag(28,0) == 1) {
day1 = (get_flag(250,4));

if (what_day_of_scenario() > (day1 + 1)) {
set_flag(28,0,2);
print_str_color("[string]",3);
}

if (get_flag(200,2) == 0) {
day1 = get_flag(250,4);
if (what_day_of_scenario() == (day1 + 1)) {
set_flag(200,2,1);
print_str_color("[string]",3);
}
}
}
(Note that there is no break; call, because I didn't copy the whole start_state)

The reason for me believing that the start_state isn't run proparly, is that the call print_num is only run once, as the digit "1" is only displayed once. However, if I insert a "set_state_continue" call in the above if-call, that state will be run over and over again...

As it is now, the start_state is only run once, and then never again. That is, until you reload your saved game or start over with the entire scenario. Then the start_state is run, and again, only for one time. Then it stops.

Anybody have an idea what could cause this? i think the above code is the culprit, as I was working on that particulair bit of the start_state when a long time ago, when it decided to malfunction.

[ Friday, May 18, 2007 06:40: Message edited by: Thralni ]

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
Master
Member # 5977
Profile Homepage #1
Yay for double posts in less than an hour.

I thought this might have been important enough for a new post, otherwise correct me, edit the previous post with what I'm saying here and delete this post.

Anyway: I noticed that I had a lot of if-calls in which I had "set_state_continue"-calls. Indeed, when I removed them all, everything worked fine. Is this a known bug in BoA, something new, or did I do something excruciatingly stupid I still don't know off what it is?

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
Off With Their Heads
Member # 4045
Profile Homepage #2
If calls have a tendency to get things not to run if you're not careful, but just because you might be careless with the condition, not because of any bug.

Do you have anything before the print_num(a) call in the START_STATE?

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Raven v. Writing Desk
Member # 261
Profile Homepage #3
One other possibility that jumps to mind is that at some point in the code after the section you copied, you get stuck in a loop.

--------------------
Slarty vs. DeskDesk vs. SlartyTimeline of ErmarianG4 Strategy Central
Posts: 3560 | Registered: Wednesday, November 7 2001 08:00
Lifecrafter
Member # 6193
Profile Homepage #4
If you use set_state_continue in the start_state, it will not come back and run the remainder of the start_state. So if the first lines are if(1) set_state_continue() the rest of your start_state will never be run.

--------------------
Guaranteed to blow your mind.

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Master
Member # 5977
Profile Homepage #5
Kelandon: I checked all consitions probably a hundred times by now. It's all as it should be, in the right place, with the right condition, using the right flag, to be checked for the intended value. So there is no problem there.

No, I have placed nothing before the print_num(a) call.

Slartucker: I don't have any loop anywhere, and even if I did, I assume that the whole game would then freeze and not let me play on. Correct me if I'm wrong.

Lazarus: Yes, I know. That's just how the call works, and I know that. Problem is, is that the start_sate is never run anymore (this means it never seems to be run when I take a step, switch places or do something else that should make the start_state run), until I reload. Then the start state is run the first time, when I take a step, and all other steps I take don't trigger the start_state. Instead the state is triggered to which the set_state_continue call pointed.

Okay, time for a small progress update, and the way I came to the conclusion in my last post. I was talking to Nikki, who advised me to get all code out of the start_state and replace it with a print_num call, so i could start checking what bit of code is the culprit, giving me this:

beginstate START_STATE;
print_num(a);
break;
After that, I slowly started adding in all code that was previously in the start_state. The start_state started malfunctioning when I entered this code:

day5 = what_day_of_scenario();

if (day5 >= 120) {
day4 = (day5 - 120);
set_state_continue(13);
}

[a lot more if call like the above anbd below examples were here, but I took them out for now]

if (day5 < 12) {
day4 = day5;
set_state_continue(13);
}
The code started working again when I did this:

if (day5 >= 120) {
day4 = (day5 - 120);
// set_state_continue(13);
}

[a lot more if call like the above anbd below examples were here, but I took them out for now]

if (day5 < 12) {
day4 = day5;
// set_state_continue(13);
}
The reason I suspected the set_state_continue, was that I had taken out such a call in another place in the same start_state, and that managed to make things work just a bit better, so I thought I'd try it again, and it worked. Now, this is all very unfortunate, but really not such a big problem. I can just put in state 13 in all those if calls and be done with it. I'd just like to know why this happens, because I can't see anything obvious about it...

I checked all my other scripts to see if there was any other place in which this could occur but didn't. I found one script in which I had put a set_state_continue, but this wasn't very alarming, as it was the only state in the start_state and therefor didn't make things complicated.

[ Friday, May 18, 2007 11:13: Message edited by: Thralni ]

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
Off With Their Heads
Member # 4045
Profile Homepage #6
If you really want an explanation, I think you need to post the whole START_STATE.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Master
Member # 5977
Profile Homepage #7
beginstate START_STATE;

// The thing with appointment mayor of Filberton

a = 1;
print_num(a);

if (get_flag(28,0) == 1) {
day1 = (get_flag(250,4));

if (what_day_of_scenario() > (day1 + 1)) {
set_flag(28,0,2);
print_str_color("[string]",3);
}

if (get_flag(200,2) == 0) {
day1 = get_flag(250,4);
if (what_day_of_scenario() == (day1 + 1)) {
set_flag(200,2,1);
print_str_color("[string]",3);
}
}
}

// The arrest of commander Johnson in Fort Filbert

if (get_flag(28,1) == 2) {
if (get_flag(12,11) == 0) {
day2 = get_flag(250,5);
if (what_day_of_scenario() == (day2 + 2)) {
set_flag(12,11,1);
}
}
}

// The destruction of the empire HQ and consequences

if (get_flag(12,11) != 1) {
if (get_flag(41,0) == 0) {
if (get_flag(121,0) == 0) {
if (what_day_of_scenario() >= 10) {
set_flag(121,0,1);
set_town_visibility(18,1);
message_dialog("[string]","");
}
}
}
}

// Sheep disappearing in town 16

day5 = what_day_of_scenario();

if (day5 >= 120) {
day4 = (day5 - 120);
set_state_continue(13);
}

if (day5 >= 108) {
day4 = (day5 - 108);
set_state_continue(13);
}

if (day5 >= 96) {
day4 = (day5 - 96);
set_state_continue(13);
}

if (day5 >= 84) {
day4 = (day5 - 84);
set_state_continue(13);
}

if (day5 >= 72) {
day4 = (day5 - 72);
set_state_continue(13);
}

if (day5 >= 60) {
day4 = (day5 - 60);
set_state_continue(13);
}

if (day5 >= 48) {
day4 = (day5 - 48);
set_state_continue(13);
}

if (day5 >= 36) {
day4 = (day5 - 36);
set_state_continue(13);
}

if (day5 >= 24) {
day4 = (day5 - 24);
set_state_continue(13);
}

if (day5 >= 12) {
day4 = (day5 - 12);
set_state_continue(13);
}

if (day5 < 12) {
day4 = day5;
set_state_continue(13);
}
break;


[ Friday, May 18, 2007 12:34: Message edited by: Thralni ]

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
Infiltrator
Member # 5576
Profile Homepage #8
I tested it, and it really does seem to execute state 13 over and over again without ever going back to the START_STATE. However, I was able to fix it by putting set_state(START_STATE);at the end of state 13. Also, Thralni, you should really use day4 = day5 % 12; instead of that huge set of if statements.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
Master
Member # 5977
Profile Homepage #9
Yeah, I probably should, though I made that script when I was very unexperienced and had no idea of all these mathematical expressions. thanks for the tip, I'll defintely use it.

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00