1 registered members (henrybane),
1,182
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Enduriel
OP
Member
|
OP
Member
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
Serious User
|
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 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
Enduriel
OP
Member
|
OP
Member
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
|
wow man thanks now this gives me some good ideas how to improve the code <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: Scorpion]
#220852
08/10/08 11:04
08/10/08 11:04
|
Joined: Aug 2008
Posts: 133 Sweden, Stockholm
Enduriel
OP
Member
|
OP
Member
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
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
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
try this 1st of all and let me know...
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: Enduriel]
#220862
08/10/08 12:37
08/10/08 12:37
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
yeah there's 3 of those! damn copy'n'paste
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* 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 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
Enduriel
OP
Member
|
OP
Member
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.
|
|
|
|