Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,182 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
how do you use goto OUTSIDE brackets? #220780
08/09/08 12:30
08/09/08 12:30
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
so my problem is a7 too lite-c with the goto someplace; instruction. I've searched the forum and people say it was removed in lite-c/limited in lite-c so it only works inside brackets. now I need another code to make this work. I've tried switch (var)
case0
case1
etc etc but I couldn't get it to work properly =/




Here is the code:

PS: now I haven't started to change this to lite-c but I know that the goto instruction doens't work from my previous convertion, and I have no idea how to ignore some of my code with goto instructions depending on variable statuses just like below. If I don't do it like this I will get errors with my game and I seriously need to find a way to make the goto instruction to WORK outside brackets. This is the attack script in an final fantasy turn based game. But don't change the code entirly to lite-c, just show me a good example how to replace goto in lite-c.


function attack_script (caster, defender)
{
temp_caster = caster;
temp_defender = defender;
freeze_someone(temp_caster);
vec_set(target_location.x, temp_defender.x);
if (temp_caster.x > temp_defender.x) {target_location.x += 50;} else {target_location.x -= 50;}
move_to_location(temp_caster, target_location, yes);
get_casters_frames();
animate_caster_cycle(temp_caster_frames[run_start], temp_caster_frames[run_end], 1.5);
while (in_progress == yes) {wait(1);}
end_animate_caster_cycle = yes;
animate_caster(temp_caster_frames[attack_start], temp_caster_frames[attack_end], 1.8, yes);
while (in_progress == yes) {wait(1);}



/////////////////Randomize attack, if miss then goto skip the rest of the code so no damage is done.
randomize();
temp = random(100);
if (int(temp) < 10)
{
vec_set(temp,temp_defender.x);
vec_to_screen(temp, field_camera);

miss_text.pos_x = temp.x - 23;
miss_text.pos_y = temp.y - 70;

miss_text.visible = on;
sleep(1);
miss_text.visible = off;

goto skip;

}





get_casters_stats();
get_defenders_stats();

damage = ((temp_caster_stats[atk])*2) - temp_defender_stats[def];
damage = max(damage, 0);

temp_defender_stats[current_hp] -= damage;
temp_defender_stats[current_hp] = max(temp_defender_stats[current_hp], 0);

affect_defenders_stats();
if (temp_defender_stats[current_hp] <= 0) {temp_defender_die();}


vec_set(temp,temp_defender.x);
vec_to_screen(temp, field_camera);
damage_pan.pos_x = temp.x - 23;
damage_pan.pos_y = temp.y - 70;
damage_pan.visible = on;
sleep(1);
damage_pan.visible = off;


/////////////here is where skip2 is, it is made so WHEN player attacks himself and he dies, he doesn't rotate and run back to his position

if (temp_defender_stats[current_hp] <= 0) && (temp_caster) == (temp_defender) {freeze_someone(temp_defender); goto skip2;}





/////////////here is where randomize attack skips too!
skip:


temp_caster.pan -= 180;
get_starting_location(temp_caster);
move_to_location(temp_caster, starting_location, yes);
animate_caster_cycle(temp_caster_frames[run_start], temp_caster_frames[run_end], 1.5);
while (in_progress == yes) {wait(1);}
end_animate_caster_cycle = yes;
temp_caster.pan += 180;
unfreeze_someone(temp_caster);





//////////////skip2 is here
skip2:


wait(1);

death_check();
wait(1);
turn_check();

}




this code works with a7 c-script, but in lite-c I can't use goto to jump outside brackets =/ and I have no idea how to fix this.

Re: how do you use goto OUTSIDE brackets? [Re: Enduriel] #220786
08/09/08 13:35
08/09/08 13:35
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
http://xkcd.com/292/

I'll look at your code..but wheres the problem to post it in 2 little code-tags? That would make it much easyier for people to look at it...please do that

Code:
function attack_script (caster, defender)
{
	int noAttack = 0;
	int playerDied = 0;
	temp_caster = caster;
	temp_defender = defender;
	freeze_someone(temp_caster);
	vec_set(target_location.x, temp_defender.x);
	if (temp_caster.x > temp_defender.x) {target_location.x += 50;} else {target_location.x -= 50;}
	move_to_location(temp_caster, target_location, yes);
	get_casters_frames();
	animate_caster_cycle(temp_caster_frames[run_start], temp_caster_frames[run_end], 1.5);
	while (in_progress == yes) {wait(1);}
	end_animate_caster_cycle = yes;
	animate_caster(temp_caster_frames[attack_start], temp_caster_frames[attack_end], 1.8, yes);
	while (in_progress == yes) {wait(1);}

	/////////////////Randomize attack, if miss then goto skip the rest of the code so no damage is done.
	randomize();
	temp = random(100);
	if (int(temp) < 10)
	{
		vec_set(temp,temp_defender.x);
		vec_to_screen(temp, field_camera);

		miss_text.pos_x = temp.x - 23;
		miss_text.pos_y = temp.y - 70;

		miss_text.visible = on;
		wait(-1);
		miss_text.visible = off;

		noAttack = 1;

	}



	if(noAttack==0){
		get_casters_stats();
		get_defenders_stats();

		damage = ((temp_caster_stats[atk])*2) - temp_defender_stats[def];
		damage = max(damage, 0);

		temp_defender_stats[current_hp] -= damage;
		temp_defender_stats[current_hp] = max(temp_defender_stats[current_hp], 0);

		affect_defenders_stats();
		if (temp_defender_stats[current_hp] <= 0) {temp_defender_die();}


		vec_set(temp,temp_defender.x);
		vec_to_screen(temp, field_camera);
		damage_pan.pos_x = temp.x - 23;
		damage_pan.pos_y = temp.y - 70;
		damage_pan.visible = on;
		wait(-1);
		damage_pan.visible = off;
		if(temp_defender_stats[current_hp] <= 0) && (temp_caster) == (temp_defender) {freeze_someone(temp_defender); playerDied=1;}
		
	}


	if(playerDied==0){

		temp_caster.pan -= 180;
		get_starting_location(temp_caster);
		move_to_location(temp_caster, starting_location, yes);
		animate_caster_cycle(temp_caster_frames[run_start], temp_caster_frames[run_end], 1.5);
		while (in_progress == yes) {wait(1);}
		end_animate_caster_cycle = yes;
		temp_caster.pan += 180;
		unfreeze_someone(temp_caster);
	}


	wait(1);

	death_check();
	wait(1);
	turn_check();

}


It's not really the best code...I just created 2 local variables and check them by 2 if functions. I'm sure there are a lot of better ways to do it, but I don't have the time for it. (I also replaced sleep(1), which is obsolete syntax by wait(-1))

Last edited by Scorpion; 08/09/08 13:48. Reason: added new code
Re: how do you use goto OUTSIDE brackets? [Re: Scorpion] #220791
08/09/08 14:17
08/09/08 14:17
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
wow man thanks laugh now this gives me some good ideas how to improve the code laugh
<3 u!

and yeah I will do [code] from now on but I wanted to mark the gotos with red color that's why I didn't use it =)

Last edited by Enduriel; 08/09/08 14:18.
Re: how do you use goto OUTSIDE brackets? [Re: Enduriel] #220794
08/09/08 15:50
08/09/08 15:50
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
You can use both with this forum software afaik smile

Re: how do you use goto OUTSIDE brackets? [Re: Scorpion] #220852
08/10/08 11:04
08/10/08 11:04
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
Nah colors inside code doens't work for me :<

Hey scorpion, this is one last favor I want to ask you :p it's about goto again, but a more complex one. I couldn't get it to work properly with local variables and the command continue;

could you please help me with this one? there is 4 gotos called several times, those gotos are Out: goback: loop: and skip:

I'm almost done with translating the whole project from c-script to lite-c, only the main menu code is left and this one

Code:


function select_magic()
{

wait(1);


set(bolt_text,VISIBLE); selected = bolt_selected;

if (cure_prop[available] == yes) {set(cure_text,VISIBLE);}
if (fire_prop[available] == yes) {set(fire_text,VISIBLE);}
if (know_cure == yes) {set(cure_text_gray,VISIBLE);}
if (know_fire == yes) {set(fire_text_gray,VISIBLE);}

set(arrow,VISIBLE);

while(key_shift == 1) {wait(1);}
while(1)
	{
	if (key_ctrl == 1) {goto goback;}

loop:
	if (selected == bolt_selected)
	{
		if (bolt_prop[available] == no)
		{
			if (key_s == 1) {selected = cure_selected; goto skip;}

			if (key_w == 1) {selected = fire_selected; goto skip;}
			selected = cure_selected; goto skip;
		}
		arrow.pos_x = 320; arrow.pos_y = 350;
		if (already_pushed == no)
		{
			if (key_s == 1) {selected = cure_selected; already_pushed = yes; goto loop;}
			if (key_w == 1) {selected = fire_selected; already_pushed = yes; goto loop;}
		}
	}
	if (selected == cure_selected)
	{
		if (cure_prop[available] == no)
		{
			if (key_s == 1) {selected = fire_selected; goto skip;}
			if (key_w == 1) {selected = bolt_selected; goto skip;}
			selected = fire_selected; goto skip;
		}
		arrow.pos_x = 320; arrow.pos_y = 390;
		if (already_pushed == no)
		{
			if (key_s == 1) {selected = fire_selected; already_pushed = yes; goto loop;}
			if (key_w == 1) {selected = bolt_selected; already_pushed = yes; goto loop;}
		}
	}
	if (selected == fire_selected)
	{
		if (fire_prop[available] == no)
		{
			if (key_s == 1) {selected = bolt_selected; goto skip;}
			if (key_w == 1) {selected = cure_selected; goto skip;}
			selected = fire_selected; goto skip;
		}
		arrow.pos_x = 320; arrow.pos_y = 430;
		if (already_pushed == no)
		{
			if (key_s == 1) {selected = bolt_selected; already_pushed = yes; goto loop;}
			if (key_w == 1) {selected = cure_selected; already_pushed = yes; goto loop;}
		}
	}
	if ((key_s == 1)||(key_w == 1)) {wait(-0.1);}
	already_pushed = no;
	
skip:
	if (key_shift == 1)

	{
		if ((whos_turn == heru) && (selected == bolt_selected)) {select_target(heru,bolt_prop);}
		if ((whos_turn == heru) && (selected == cure_selected)) {select_target(heru,cure_prop);}
		if ((whos_turn == heru) && (selected == fire_selected)) {select_target(heru,fire_prop);}

		if ((whos_turn == white_mage) && (selected == bolt_selected)) {select_target(white_mage,bolt_prop);}
		if ((whos_turn == white_mage) && (selected == cure_selected)) {select_target(white_mage,cure_prop);}
		if ((whos_turn == white_mage) && (selected == fire_selected)) {select_target(white_mage,fire_prop);}

		reset(selector, VISIBLE);
		goto out;
	}


	wait(1);
}

goback:
    if (whos_turn == white_mage) {whitemage_turn();}
    if (whos_turn == heru) {heru_turn();}

out:
   reset(bolt_text,VISIBLE);
   reset(cure_text,VISIBLE);
   reset(fire_text,VISIBLE);
   reset(bolt_text_gray,VISIBLE);
   reset(cure_text_gray,VISIBLE);
   reset(fire_text_gray,VISIBLE);
   reset(arrow,VISIBLE);
}




Last edited by Enduriel; 08/10/08 11:43.
Re: how do you use goto OUTSIDE brackets? [Re: Enduriel] #220859
08/10/08 12:10
08/10/08 12:10
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
try this 1st of all and let me know... smile

Code:
function select_magic()
{
	wait(1);
	
	set(bolt_text,VISIBLE); selected = bolt_selected;

	if (cure_prop[available] == yes) {set(cure_text,VISIBLE);}
	if (fire_prop[available] == yes) {set(fire_text,VISIBLE);}
	if (know_cure == yes) {set(cure_text_gray,VISIBLE);}
	if (know_fire == yes) {set(fire_text_gray,VISIBLE);}

	set(arrow,VISIBLE);
	
	while(key_shift == 1) {wait(1);}

	while(1)
	{
		if (key_ctrl == 1)
		{
			if (whos_turn == white_mage) {whitemage_turn();} //your original goback:
			if (whos_turn == heru) {heru_turn();}
			break; //your original out:
		}

		if (selected == bolt_selected)
		{
			if (bolt_prop[available] == no)
			{
				if (key_s == 1) {selected = cure_selected; break;} //goto skip;}
	
				if (key_w == 1) {selected = fire_selected; break;} // goto skip;}
				selected = cure_selected; break;} // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 350;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = cure_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = fire_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if (selected == cure_selected)
		{
			if (cure_prop[available] == no)
			{
				if (key_s == 1) {selected = fire_selected; break;} // goto skip;}
				if (key_w == 1) {selected = bolt_selected; break;} // goto skip;}
				selected = fire_selected; break;} // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 390;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = fire_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = bolt_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if (selected == fire_selected)
		{
			if (fire_prop[available] == no)
			{
				if (key_s == 1) {selected = bolt_selected; break;} // goto skip;}
				if (key_w == 1) {selected = cure_selected; break;} // goto skip;}
				selected = fire_selected; break;} // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 430;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = bolt_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = cure_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if ((key_s == 1)||(key_w == 1)) {wait(-0.1);}
		already_pushed = no;

		wait(1);
	}

	if (key_shift)
	{
		if ((whos_turn == heru) && (selected == bolt_selected)) {select_target(heru,bolt_prop);}
		if ((whos_turn == heru) && (selected == cure_selected)) {select_target(heru,cure_prop);}
		if ((whos_turn == heru) && (selected == fire_selected)) {select_target(heru,fire_prop);}

		if ((whos_turn == white_mage) && (selected == bolt_selected)) {select_target(white_mage,bolt_prop);}
		if ((whos_turn == white_mage) && (selected == cure_selected)) {select_target(white_mage,cure_prop);}
		if ((whos_turn == white_mage) && (selected == fire_selected)) {select_target(white_mage,fire_prop);}

		reset(selector, VISIBLE);
		break; //your original out:
	}

	reset(bolt_text,VISIBLE);
	reset(cure_text,VISIBLE);
	reset(fire_text,VISIBLE);
	reset(bolt_text_gray,VISIBLE);
	reset(cure_text_gray,VISIBLE);
	reset(fire_text_gray,VISIBLE);
	reset(arrow,VISIBLE);
}

it could still be improved further

Re: how do you use goto OUTSIDE brackets? [Re: MrGuest] #220860
08/10/08 12:30
08/10/08 12:30
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
Tried and I saw that there are some missing/too much brackets where u inserted the breaks, so I fixed it and now it crashed when engine is run :< trying to fix it atm but don't know where the error is cause tehre is no syntax problems

Re: how do you use goto OUTSIDE brackets? [Re: Enduriel] #220861
08/10/08 12:31
08/10/08 12:31
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
Okay fixed the crash it was because u inserted a break; in a IF(){} :P

gonna test it now

Re: how do you use goto OUTSIDE brackets? [Re: Enduriel] #220862
08/10/08 12:37
08/10/08 12:37
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
yeah there's 3 of those! damn copy'n'paste

Code:
function select_magic()
{
	wait(1);
	
	set(bolt_text,VISIBLE); selected = bolt_selected;

	if (cure_prop[available] == yes) {set(cure_text,VISIBLE);}
	if (fire_prop[available] == yes) {set(fire_text,VISIBLE);}
	if (know_cure == yes) {set(cure_text_gray,VISIBLE);}
	if (know_fire == yes) {set(fire_text_gray,VISIBLE);}

	set(arrow,VISIBLE);
	
	while(key_shift == 1) {wait(1);}

	while(1)
	{
		if (key_ctrl == 1)
		{
			if (whos_turn == white_mage) {whitemage_turn();} //your original goback:
			if (whos_turn == heru) {heru_turn();}
			break; //your original out:
		}

		if (selected == bolt_selected)
		{
			if (bolt_prop[available] == no)
			{
				if (key_s == 1) {selected = cure_selected; break;} //goto skip;}
	
				if (key_w == 1) {selected = fire_selected; break;} // goto skip;}
				selected = cure_selected; break; // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 350;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = cure_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = fire_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if (selected == cure_selected)
		{
			if (cure_prop[available] == no)
			{
				if (key_s == 1) {selected = fire_selected; break;} // goto skip;}
				if (key_w == 1) {selected = bolt_selected; break;} // goto skip;}
				selected = fire_selected; break; // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 390;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = fire_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = bolt_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if (selected == fire_selected)
		{
			if (fire_prop[available] == no)
			{
				if (key_s == 1) {selected = bolt_selected; break;} // goto skip;}
				if (key_w == 1) {selected = cure_selected; break;} // goto skip;}
				selected = fire_selected; break; // goto skip;
			}
			arrow.pos_x = 320; arrow.pos_y = 430;
			if (already_pushed == no)
			{
				if (key_s == 1) {selected = bolt_selected; already_pushed = yes; continue;} // goto loop;}
				if (key_w == 1) {selected = cure_selected; already_pushed = yes; continue;} // goto loop;}
			}
		}
		if ((key_s == 1)||(key_w == 1)) {wait(-0.1);}
		already_pushed = no;

		wait(1);
	}

	if (key_shift)
	{
		if ((whos_turn == heru) || (whos_turn == white_mage)) //only needs this check if more possible outcomes for whos_turn
		{
			if (selected == bolt_selected) {select_target(whos_turn,bolt_prop);}
			if (selected == cure_selected) {select_target(whos_turn,cure_prop);}
			if (selected == fire_selected) {select_target(whos_turn,fire_prop);}
		}

/*		if ((whos_turn == heru) && (selected == bolt_selected)) {select_target(heru,bolt_prop);}
		if ((whos_turn == heru) && (selected == cure_selected)) {select_target(heru,cure_prop);}
		if ((whos_turn == heru) && (selected == fire_selected)) {select_target(heru,fire_prop);}

		if ((whos_turn == white_mage) && (selected == bolt_selected)) {select_target(white_mage,bolt_prop);}
		if ((whos_turn == white_mage) && (selected == cure_selected)) {select_target(white_mage,cure_prop);}
		if ((whos_turn == white_mage) && (selected == fire_selected)) {select_target(white_mage,fire_prop);}*/

		reset(selector, VISIBLE);
		break; //your original out:
	}


i've added another change to the if ((whos_turn bit and commented out the original... have a look to see if you need the 1st check too

also check these 3 bits of code, i think you're sending the wrong selected *skills*
Code:
if (selected == bolt_selected)
		{
			if (bolt_prop[available] == no)
			{
				if (key_s == 1) {selected = cure_selected; break;} //goto skip;}
	
				if (key_w == 1) {selected = fire_selected; break;} // goto skip;}
				  selected = cure_selected; break; // goto skip; 


shouldn't that be
Code:
selected = bolt_selected; break
(same applies to cure too)

Last edited by MrGuest; 08/10/08 12:49. Reason: Queries
Re: how do you use goto OUTSIDE brackets? [Re: MrGuest] #220863
08/10/08 12:46
08/10/08 12:46
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline OP
Member
Enduriel  Offline OP
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm
It works but when I cycle through bolt and cure it freezes after like 5 or 6 times :<

and you forgot to include those at the end :P

reset(bolt_text,VISIBLE);
reset(cure_text,VISIBLE);
reset(fire_text,VISIBLE);
reset(bolt_text_gray,VISIBLE);
reset(cure_text_gray,VISIBLE);
reset(fire_text_gray,VISIBLE);
reset(arrow,VISIBLE);


Last edited by Enduriel; 08/10/08 12:50.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1