Switch issues [Solved] - ProyectV - 04-20-2014
Well, this is my headache. For some reason that a i don't understand the switch only reads the case 1 and stays there. It dosen't do the other cases and it's been bothering me for about 5 to 6 hours. Help would be appreciated...
Spoiler below!
void IntroSetUp(bool IntroEscene)
{
if(IntroEscene)
{
FadeOut(0.0f);
SetPlayerRunSpeedMul(0.0f);
SetPlayerMoveSpeedMul(0.0f);
SetPlayerLookSpeedMul(0.03f);
SetPlayerCrouching(true);
SetPlayerCrouchDisabled(true);
SetPlayerJumpDisabled(true);
SetInventoryDisabled(true);
MovePlayerHeadPos(0.5f, -0.3f, 0.0f, 1.0f, 0.1f);
AddTimer("IntroMapa", 2.0f, "IntroMapa");
}
}
void IntroMapa(string &in asTimer) ///////revisar más tarde....
{
bool bPauseAtStep = false;
string sIntro = asTimer;
AddLocalVarInt(sIntro, 1);
float fEventSpeed = 1.0f;
switch(GetLocalVarInt(sIntro))
{
case 1:
PlayGuiSound("justine_wake2.ogg", 1.0f);
FadeIn(4.0f);
SetPlayerLookSpeedMul(0.06f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
StartPlayerLookAt("IntroArea", 2.0f, 2.0f, "");
fEventSpeed = 2.0f;
break;
case 2:
StartPlayerLookAt("IntroArea_1", 2.0f, 2.0f, "");
break;
case 3:
StartPlayerLookAt("IntroArea_2", 2.0f, 2.0f, "");
FadeOut(3.0f);
break;
case 4:
FadeIn(1.0f);
StartPlayerLookAt("IntroArea_3", 2.0f, 2.0f, "");
fEventSpeed = 6.0f;
break;
case 5:
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("fluttersuitor_NPC_1", "PathNodeArea_5", 0, "");
fEventSpeed = 10.0f;
break;
case 6:
FadeOut(2.0f);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
TeleportPlayer("StartArea");
break;
case 7:
FadeIn(1.0f);
PlaySoundAtEntity("", "react_sigh.snt", "Player", 0, false);
SetPlayerMoveSpeedMul(0.4f);
SetPlayerLookSpeedMul(0.5f);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
fEventSpeed = 3.0f;
break;
case 8:
SetPlayerCrouching(false);
PlaySoundAtEntity("", "player_stand.snt", "Player", 0, false);
MovePlayerHeadPos(0, 0, 0.0f, 0.5f, 0.1f);
SetPlayerMoveSpeedMul(0.6f);
SetPlayerLookSpeedMul(0.8f);
fEventSpeed = 1.0f;
break;
case 9:
SetPlayerCrouching(true);
PlaySoundAtEntity("", "step_walk_rock.snt", "Player", 0, false);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
fEventSpeed = 1.0f;
break;
case 10:
MovePlayerHeadPos(0, 0, 0.0f, 0.0f, 0.0f);
SetPlayerMoveSpeedMul(0.8f);
SetPlayerLookSpeedMul(1.0f);
SetPlayerCrouchDisabled(false);
SetPlayerJumpDisabled(false);
SetInventoryDisabled(false);
StopPlayerLookAt();
break;
default:
bPauseAtStep = true;
break;
}
if(!bPauseAtStep)
AddTimer("", 5.0f, "StartBreakFree");
}
RE: Switch issues - Mudbill - 04-20-2014
Let's analyze what's happening here:
First we add a timer named IntroMapa . Where is this added from? I don't see what's executing it. I think we'll need the name of that timer to know how things work here.
Let's assume it's named timer . String sIntro will now be named "timer".
After that it will add a variable to a new variable named what sIntro is. Basically it creates an int variable named "timer" and sets it to 1.
Later, in the switch statement, it checks for the value of sIntro (the int value of the variable named by the string of sIntro). Basically, if int "timer" is 1 (which it should be at this point), it runs case 1. So far so good.
But what happens next? How many times is this timer called? I think that makes the big difference here. Nothing would happen after case 1 if this is the only time, because there's nothing in there that adds another value or calls the timer again.
PS: This will probably be moved to the Development Support section soon.
RE: Switch issues - ProyectV - 04-22-2014
(04-20-2014, 11:50 PM) Mudbill Wrote: But what happens next? How many times is this timer called? I think that makes the big difference here. Nothing would happen after case 1 if this is the only time, because there's nothing in there that adds another value or calls the timer again.
I think that i know what to do... maybe with a "while" statement i can make the function work and then stop it, maybe...
RE: Switch issues - Daemian - 04-22-2014
Mudbill means you need to add a timer somewhere to call the function multiple times, cause right now it's running only once.
Also, make sure the variable named "IntroMapa" is declared before you call that function.
SetLocalVarInt( "IntroMapa", 0 );
(The one where you're storing the increasing int)
And I don't think a Do-While operator it's the best solution for your situation, since there's no way to pause a loop.
RE: Switch issues - PutraenusAlivius - 04-22-2014
Amn is right, there is no way to pause a loop. You can only wait until what it wants is fulfilled.
The reason that it stays in Case 1 is that because of the condition. You declared sIntro 1 and so it's gonna check 1 because the only matching case is Case 1 . If you declare sIntro to be 2 or 3, then the case being checked is the one that correspond with the declared condtion. If sIntro is 2 then the one checked is Case 2 . If it's 3 then the case checked is Case 3 and so on.
RE: Switch issues - Mudbill - 04-22-2014
I got a feeling that this is not your whole script, so where is the rest? This code is incomplete as it is, because we need to know where it's called from and how it's being called. I think that's all that remains. If you've already set up a timer loop that calls it, then we can figure out the problem there, but if not, this code won't do much until it's finished.
RE: Switch issues - ProyectV - 04-22-2014
Well... this is my whole script so far...
Spoiler below!
void OnStart()
{
AddUseItemCallback("", "stone_hammer_1", "wooden_boards_block_1", "Break_Free", true);
AddEntityCollideCallback("Player", "ScriptDamage01", "Hurt01", true, 1);
AddUseItemCallback("", "string_pile_1", "ScriptArea_2", "Rope_Ladder", true);
AddEntityCollideCallback("bed_simple_movable_10", "ScriptArea_3", "Scare01", true, 1);
SetEntityPlayerInteractCallback("string_pile_1", "Scare02", true);
AddEntityCollideCallback("servant_grunt_1", "PathNodeArea_3", "Hallucination01", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_6", "Save01", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_7", "Memento1", true, 1);
AddEntityCollideCallback("fluttersuitor_NPC_1", "PathNodeArea_5", "EndIntroPart1", true, 1);
AddEntityCollideCallback("servant_grunt_1", "PathNodeArea_4", "EndIntroPart2", true, 1);
AddLocalVarInt("Death", 0);
AddQuest("Castel", "Castel");
AddLocalVarInt("Hole01", 0);
AddLocalVarInt("Memento01", 0);
bool IntroEscene = true;
IntroSetUp(IntroEscene);
}
void OnEnter()
{
}
void OnLeave()
{
PreloadSound("door_level_cistern_open");
}
void IntroSetUp(bool IntroEscene)
{
if(IntroEscene){
for(int i=0;i<10;++i) {
AddTimer("IntroMapa", 2.0f, "IntroMapa");
}
FadeOut(0.0f);
SetPlayerRunSpeedMul(0.0f);
SetPlayerMoveSpeedMul(0.0f);
SetPlayerLookSpeedMul(0.03f);
SetPlayerCrouching(true);
SetPlayerCrouchDisabled(true);
SetPlayerJumpDisabled(true);
SetInventoryDisabled(true);
MovePlayerHeadPos(0.5f, -0.3f, 0.0f, 1.0f, 0.1f);
}
}
void IntroMapa(string &in asTimer) ///////revisar más tarde....
{
bool bPauseAtStep = false;
string sIntro = asTimer;
float fEventSpeed = 1.0f;
AddLocalVarInt(sIntro, 0);
for(int i=sIntro;i<10;++i) {
}
switch(GetLocalVarInt(sIntro))
{
case 1:
FadeIn(4.0f);
PlayGuiSound("justine_wake2.ogg", 1.0f);
SetPlayerLookSpeedMul(0.06f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
StartPlayerLookAt("IntroArea", 2.0f, 2.0f, "");
fEventSpeed = 2.0f;
break;
case 2:
StartPlayerLookAt("IntroArea_1", 2.0f, 2.0f, "");
break;
case 3:
StartPlayerLookAt("IntroArea_2", 2.0f, 2.0f, "");
FadeOut(3.0f);
break;
case 4:
FadeIn(1.0f);
StartPlayerLookAt("IntroArea_3", 2.0f, 2.0f, "");
fEventSpeed = 6.0f;
break;
case 5:
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("fluttersuitor_NPC_1", "PathNodeArea_5", 0, "");
fEventSpeed = 10.0f;
break;
case 6:
FadeOut(2.0f);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
TeleportPlayer("StartArea");
break;
case 7:
FadeIn(1.0f);
PlaySoundAtEntity("", "react_sigh.snt", "Player", 0, false);
SetPlayerMoveSpeedMul(0.4f);
SetPlayerLookSpeedMul(0.5f);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
fEventSpeed = 3.0f;
break;
case 8:
SetPlayerCrouching(false);
PlaySoundAtEntity("", "player_stand.snt", "Player", 0, false);
MovePlayerHeadPos(0, 0, 0.0f, 0.5f, 0.1f);
SetPlayerMoveSpeedMul(0.6f);
SetPlayerLookSpeedMul(0.8f);
fEventSpeed = 1.0f;
break;
case 9:
SetPlayerCrouching(true);
PlaySoundAtEntity("", "step_walk_rock.snt", "Player", 0, false);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
fEventSpeed = 1.0f;
break;
case 10:
MovePlayerHeadPos(0, 0, 0.0f, 0.0f, 0.0f);
SetPlayerMoveSpeedMul(0.8f);
SetPlayerLookSpeedMul(1.0f);
SetPlayerCrouchDisabled(false);
SetPlayerJumpDisabled(false);
SetInventoryDisabled(false);
StopPlayerLookAt();
break;
default:
bPauseAtStep = true;
break;
}
if(!bPauseAtStep)
AddTimer("", 5.0f, "StartBreakFree");
}
void EndIntroPart1(string &in asParent, string &in asChild, int alState)
{
FadeEnemyToSmoke("fluttersuitor_NPC_1", false);
}
void EndIntroPart2(string &in asParent, string &in asChild, int alState)
{
FadeEnemyToSmoke("servant_grunt_2", false);
}
void Break_Free(string &in asItem, string &in asEntity)
{
SetPropHealth("wooden_boards_block_1", 0.0f);
SetEntityActive("wooden_boards_block_broken_1", true);
RemoveItem(asItem);
SetEntityActive("wooden_boards_block_1", false);
PlaySoundAtEntity("", "break_wood.snt", "ScriptArea_1", 0, false);
}
void Hurt01(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("Death")==0)
{
GivePlayerDamage(100.0f, "(BloodSplat", true, true);
}
}
void Rope_Ladder(string &in asItem, string &in asEntity)
{
SetEntityActive("LadderArea_2", true);
RemoveItem(asItem);
SetLocalVarInt("Death", 1);
}
void Scare01(string &in asParent, string &in asChild, int alState)
{
FadeSepiaColorTo(0.0f, 2.0f);
FadeRadialBlurTo(0.0f, 2.0f);
GiveSanityDamage(10.0f, true);
PlaySoundAtEntity("", "ui_insanity_touch.snt", "ScriptArea_4", 0, false);
PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
}
void Scare02(string &in asEntity)
{
SetEntityActive("servant_grunt_1", true);
StartPlayerLookAt("ScriptArea_5", 2.0f, 2.0f, "");
AddTimer("", 3.0f, "Stoplook01");
CompleteQuest("blockedway02" ,"blockedway02");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 0, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0.001, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, "");
}
void Hallucination01(string &in asParent, string &in asChild, int alState)
{
FadeEnemyToSmoke("servant_grunt_1", false);
}
void Stoplook01(string &in asTimer)
{
PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
StopPlayerLookAt();
}
void Save01(string &in asParent, string &in asChild, int alState)
{
CheckPoint ("", "ScriptArea_6", "", "Hints", "FallDeath01");
StartPlayerLookAt("ScriptArea_8", 1.0f, 1.0f, "");
AddTimer("", 1.0f, "StopLook02");
if(GetLocalVarInt("Hole01")==0)
{
SetLocalVarInt("Memento01", 1);
SetMessage("FluttershyThougs/Talks", "DarkHole01", 0.0f);
}
else if(GetLocalVarInt("Hole01")==1)
{
SetMessage("FluttershyThougs/Talks", "DarkHole02", 0.0f);
AddQuest("blockedway02", "blockedway02");
CompleteQuest("blockedway01" ,"blockedway01");
}
}
void StartBreakFree(string &in asTimer)
{
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
SetEntityActive("stone_hammer_1", true);
AddTimer("", 2.0f, "EndBreakFree");
}
void EndBreakFree(string &in asTimer)
{
PlaySoundAtEntity("", "lock_door.snt", "Player", 0, false);
}
void Memento1(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("Memento01")==0)
{
AddQuest("blockedway01", "blockedway01");
SetLocalVarInt("Hole01", 1);
}
else if(GetLocalVarInt("Memento01")==1)
{
AddQuest("blockedway02", "blockedway02");
}
}
void StopLook02(string &in asTimer)
{
StopPlayerLookAt();
}
RE: Switch issues - Daemian - 04-23-2014
You should understand what's happening in your function before you keep adding code.
RE: Switch issues - ProyectV - 04-23-2014
OMG i can't belive i was such an idiot!!! How could i forget the basis of a switch... anyway, thanks for everything, it's already solve, anyway here's the final product...
Spoiler below!
switch(GetLocalVarInt(sIntro))
{
case 1:
FadeIn(4.0f);
PlayGuiSound("justine_wake2.ogg", 1.0f);
SetPlayerLookSpeedMul(0.06f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
StartPlayerLookAt("IntroArea", 2.0f, 2.0f, "");
fEventSpeed = 2.0f;
break;
case 2:
StartPlayerLookAt("IntroArea_1", 2.0f, 2.0f, "");
break;
case 3:
StartPlayerLookAt("IntroArea_2", 2.0f, 2.0f, "");
FadeOut(3.0f);
break;
case 4:
FadeIn(1.0f);
StartPlayerLookAt("IntroArea_3", 2.0f, 2.0f, "");
fEventSpeed = 6.0f;
break;
case 5:
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("fluttersuitor_NPC_1", "PathNodeArea_5", 0, "");
fEventSpeed = 10.0f;
break;
case 6:
FadeOut(2.0f);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
TeleportPlayer("StartArea");
break;
case 7:
FadeIn(1.0f);
PlaySoundAtEntity("", "react_sigh.snt", "Player", 0, false);
SetPlayerMoveSpeedMul(0.4f);
SetPlayerLookSpeedMul(0.5f);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
fEventSpeed = 3.0f;
break;
case 8:
SetPlayerCrouching(false);
PlaySoundAtEntity("", "player_stand.snt", "Player", 0, false);
MovePlayerHeadPos(0, 0, 0.0f, 0.5f, 0.1f);
SetPlayerMoveSpeedMul(0.6f);
SetPlayerLookSpeedMul(0.8f);
fEventSpeed = 1.0f;
break;
case 9:
SetPlayerCrouching(true);
PlaySoundAtEntity("", "step_walk_rock.snt", "Player", 0, false);
MovePlayerHeadPos(0.5, -0.3f, 0.0f, 1.0f, 0.1f);
SetRadialBlurStartDist(0.3f);
FadeRadialBlurTo(0.1f, 0.1f);
fEventSpeed = 1.0f;
break;
case 10:
MovePlayerHeadPos(0, 0, 0.0f, 0.0f, 0.0f);
SetPlayerMoveSpeedMul(0.8f);
SetPlayerLookSpeedMul(1.0f);
SetPlayerCrouchDisabled(false);
SetPlayerJumpDisabled(false);
SetInventoryDisabled(false);
StopPlayerLookAt();
break;
default:
bPauseAtStep = true;
break;
}
if(GetLocalVarInt(sIntro) <10)
{
AddTimer("IntroMapa", fEventSpeed, "IntroMapa");
}
if(!bPauseAtStep)
{
AddTimer("", 5.0f, "StartBreakFree");
}
}
Of curse, it needs some changes but now the switch works!!!
Thaks for all... Especially mudbill for always being there for me.