Jump to content

Two Script Errors (Solved)


Recommended Posts

Grrr. Peer editing time again.

 

My first problem comes from a script intended to heal/charge a creature based on the current state of two SDFs. It worked fine when I linked it to some goblins to test it in a small scenario made for this purpose. Now, when I'm testing my scenario, I get:

 

perheal Error: Bad term in expression in line 57.

 

Here's the script:

Code:
// 'perheal' by Dintiradan - Version 0.2// A very simple, naive text. Creature attacks anything it hates nearby.// Once it has won, it returns to its home.// Also, each round there is a chance its HP and SP changes.// Unless Cell 5 is negative, the HP and SP will only change when the HP is below maximum.// Memory Cells://	Cell 0 - How creature moves.//		0 - If 0, wander randomly. //		1 - Stands still until a target appears.//		2 - Completely immobile, even if target appears.//	Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this //		is killed, set to 1. (Example: If cell 1 is 3 and cell 2 is 5, when//		creature is killed, sets SDF(3,5) to 1.)//	Cell 3 - Dialogue node to start with if talked to. if left at 0, this//		character doesn't talk.//	Cell 4 - Odds that creature will change HP and SP on a given turn.//		The higher the number, the less of a chance.//		If left at zero, creature changes its HP and SP every turn.//	Cell 5 - Amount that creature will have its HP and SP change.//	Cell 6,7 - When this SDF is 1, the creature can change its HP and SP.//		If both left at 0, creature always changes its HP and SP.//	Cell 8,9 - When this SDF is 1, the creature stops changing its HP and SP.//		If both left at 0, creature changes according to cells 6,7.begincreaturescript;variables;short i,target;// Make all custom changes to the displayed behaviour here.short SPARKLE_TYPE = 3; // Green healing sparklesshort SPARKLE_NUM = 4;short SOUND = 24; // Generic prieststring DISPLAYED_TEXT = " glows for a moment, and its wounds knit.";body;beginstate INIT_STATE;	if (get_memory_cell(0) == 2)		set_mobility(ME,0);	break;beginstate DEAD_STATE;	// Set the appropriate stuff done flag for this character being dead	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))		set_flag(get_memory_cell(1),get_memory_cell(2),1);break;beginstate START_STATE;	if ((get_ran(1,0,get_memory_cell(4)) == 0) &&			((get_health(ME) < get_max_health(ME)) || (get_memory_cell(5) < 0)) &&			(((get_memory_cell(6) == 0) && (get_memory_cell(7) == 0)) ||				(get_flag(get_memory_cell(6),get_memory_cell(7)) == 1)) &&			(((get_memory_cell(8) == 0) && (get_memory_cell(9) == 0)) ||				(get_flag(get_memory_cell(8),get_memory_cell(9)) != 1))) {		change_char_energy(ME,get_memory_cell(5)); *** THIS IS LINE 57 ***		change_char_health(ME,get_memory_cell(5));		put_sparkles_on_char(ME,SPARKLE_TYPE,SPARKLE_NUM);		run_animation_sound(SOUND);		print_named_str(ME,DISPLAYED_TEXT);	}		// if I have a target for some reason, go attack it	if (target_ok()) {		if (dist_to_char(get_target()) <= 16)			set_state(3);		else			set_target(ME,-1);	}		// Look for a target, attack it if visible	if (select_target(ME,8,0)) {		do_attack();		set_state(3);	}			// Have I been hit? Strike back!	if (who_hit_me() >= 0) {		set_target(ME,who_hit_me());		do_attack();		set_state(3);	}			// Otherwise, just peacefully move around. Go back to start, if I'm too far	// from where I started.	if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {		if (get_ran(1,1,100) < 40) 			return_to_start(ME,1);	}	else if (get_memory_cell(0) == 0) {		fidget(ME,25);	}	// if we're in combat and the above didn't give me anything to do, just	// stop now. Otherwise, game will keep running script, and that eats up CPU time.	if (am_i_doing_action() == FALSE)		end_combat_turn();break;beginstate 3; // attacking	if (target_ok() == FALSE)		set_state(START_STATE);	if ((get_ran(1,0,get_memory_cell(4)) == 0) &&			((get_health(ME) < get_max_health(ME)) || (get_memory_cell(5) < 0) &&			(((get_memory_cell(6) == 0) && (get_memory_cell(7) == 0)) ||				(get_flag(get_memory_cell(6),get_memory_cell(7)) == 1)) &&			(((get_memory_cell(8) == 0) && (get_memory_cell(9) == 0)) ||				(get_flag(get_memory_cell(8),get_memory_cell(9)) != 1))) {		change_char_energy(ME,get_memory_cell(5));		change_char_health(ME,get_memory_cell(5));		put_sparkles_on_char(ME,SPARKLE_TYPE,SPARKLE_NUM);		run_animation_sound(SOUND);		print_named_str(ME,DISPLAYED_TEXT);	}	do_attack();break;beginstate TALKING_STATE;	if (get_memory_cell(3) == 0) {		print_str("Talking: It doesn't respond.");		end();	}	begin_talk_mode(get_memory_cell(3));break;
In all likelihood, it's a problem with that huge conditional. I already found one missing parenthesis.

 

My second script tries to have a monster spawn in a random close location. When running it, I get:

 

t4cmine Error: Missing integer in line 23.

 

The script is:

Code:
// 4: Crystal Minebegintownscript;variables;short choice,rand_x,rand_y;short MAX_SPAWNED = 6;short SPAWN_ODDS = 5;short SPAWN_RANGE = 6;body;beginstate INIT_STATE;break;beginstate EXIT_STATE;break;beginstate START_STATE;	if ((get_flag(4,2) != 3) && (get_flag(4,1) < MAX_SPAWNED) &&			(get_ran(1,0,SPAWN_ODDS) == 0)) {*** THE FOLLOWING IS LINE 23 ****** I TRIED IT A COUPLE OF WAYS, ONE IS COMMENTED OUT ***		rand_x = get_ran(1,-SPAWN_RANGE,SPAWN_RANGE) + char_loc_x(random_party_member());		rand_y = get_ran(1,-SPAWN_RANGE,SPAWN_RANGE) + char_loc_y(random_party_member());		// if (get_ran(1,0,1) == 0)		//	rand_x = char_loc_x(random_party_member()) + get_ran(1,0,SPAWN_RANGE);		// else		//	rand_x = char_loc_x(random_party_member()) - get_ran(1,0,SPAWN_RANGE);		// if (get_ran(1,0,1) == 0)		//	rand_y = char_loc_y(random_party_member()) + get_ran(1,0,SPAWN_RANGE);		// else		//	rand_y = char_loc_y(random_party_member()) - get_ran(1,0,SPAWN_RANGE);				if ((get_terrain(rand_x,rand_y) >= 450) &&				(get_terrain(rand_x,rand_y) <= 464) &&				(char_on_loc(rand_x,rand_y) == -1)) {			if (get_ran(1,0,1) == 0) {				if (has_special_item(1) == 0)					place_monster(rand_x,rand_y,243,0); // Black Shade (Invisible)				else					place_monster(rand_x,rand_y,246,0); // Black Shade (Visible)			}			else {				if (has_special_item(1) == 0)					place_monster(rand_x,rand_y,244,0); // Guardian (Invisible)				else					place_monster(rand_x,rand_y,247,0); // Guardian (Visible)			}						play_sound(-165);			print_str("A patch of fog close to you swirls around suddenly.");			inc_flag(4,1,1);		}	}break;
I think the line numbers are reported wrong... if you need me to clarify anything just ask. Now to see if the scripts are displayed right; Notepad botches them up.

 

EDIT: Yep, it seems UBB likes my tabs better than Notepad. Sorry about the length, I wanted to include the entire scripts; I think the reported line errors are screwed up. Also, sorry about the current lack of useful comments. I can clarify something if you need me to.

 

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

(Bashes head against wall. Repeatedly.)

Link to comment
Share on other sites

By the way, if you have an excessively large number of AND operators, you can break them up.

 

Code:
 if ((get_flag(50,2) == 1) && (get_flag(51,2) == 1))
is the same as

 

Code:
 if (get_flag(50,2) == 1)     if (get_flag(51,2) == 1)  
But the second one is probably easier to read, especially if there are lots of conditions.
Link to comment
Share on other sites

Okay, got it now after taking a break then looking at it again:

 

In the first script, both conditionals had parens. problems. From now on, I'm going to solely rely on Programmer's Notepad. I played around with the second for a while; something I did made it work.

 

Don't worry: before I release the scenario, I plan to re-do the scripts for readability.

 

A bit more playing around with a creature script, and I'll have a dungeon where creatures spawn in random locations, while keeping a limit on the number of creatures (no more flooding dungeons).

 

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

IF I EVER BECOME AN EVIL OVERLORD:

When arresting prisoners, my guards will not allow them to stop and grab a useless trinket of purely sentimental value.

Link to comment
Share on other sites

Quote:
Originally written by Kelandon:
By the way, if you have an excessively large number of AND operators, you can break them up.

Code:
 if ((get_flag(50,2) == 1) && (get_flag(51,2) == 1))
is the same as

Code:
 if (get_flag(50,2) == 1)     if (get_flag(51,2) == 1)  
But the second one is probably easier to read, especially if there are lots of conditions.
Oh... Is that how one writes them? I tried them multiple times, but I never succeeded in doing it the right way. Thanks, kelandon.
Link to comment
Share on other sites

Quote:
Originally written by Lazarus.:
Edit: Stupid UBB makin me double post. I'll try to salvage this, Err, "How about those boolean opperators eh? What a group of characters!"
This bought me more joy than you can ever imagine... I need to get out more.

And to add fuel to the "&&" argument (is it an argument yet?), I tend to do it like this:

Code:
 if((get_flag(x,y) == z) && (get_flag(a,B) != c)) { 
For some reason, I think it's more clearer than writing

Code:
 if(get_flag(x,y) == z) {    if(get_flag(a,B) != c) {        do_something_here();    }}      
Link to comment
Share on other sites

Yeah, sorry about the huge, one-line conditionals. An unfortunate side-effect of taking a programming course where Perl was the language used. It became a friendly competition to see how few lines the assignments could be done in.

 

Meh. I don't mind scripts. It's the moment of satisfaction when the thing finally works, after spending a few hours rooting out one bug.

 

(And yes, the scripts work now. I've forgotten how scary black shades and guardians could be.)

 

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

IF I EVER BECOME AN EVIL OVERLORD:

My door mechanisms will be designed so that blasting the control panel on the outside seals the door and blasting the control panel on the inside opens the door, not vice versa.

Link to comment
Share on other sites

Quote:
Originally written by Lazarus.:
For the sake of your beta testers I hope its the second.
I don't really know how that would help the beta-tester. they are all as in the first example that Kelandon gave, and I really hope you don't expect that I start changing it now.

kelandon: I meant the AND-operators.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...