trying to make a combination lock without using integers. I am terrible at math.
this is what I have formulated so far. I have no idea if this will even work.
function room_RepExec()
{
if ((((but1 == true && (but2 == true) && (but3 == true) && (but4 == true)))))
lev1 = true;
}
function hbut1_AnyClick()
{
sClick.Play();{
but1 = true;
but2 = false;
but3 = false;
but4 = false;
}
if (((but2 == true) && (but4 == true) && (but3 == true))){
sClick.Play();
but1 = true;
cJojo.Say("Coordinates ready");
}}
function hbut2_AnyClick()
{
sClick.Play();
but2 = true;
but1 = false;
but3 = false;
but4 = false;
}
function hbut3_AnyClick()
{
sClick.Play();{
but3 = true;
but1 = false;
but2 = false;
but4 = false;
}
if ((but2 == true) && (but4 == true)){
sClick.Play();
but3 = true;
}}
function hbut4_AnyClick()
{
sClick.Play();{
but4 = true;
but1 = false;
but2 = false;
but3 = false;
}
if (but2 == true){
sClick.Play();
but4 = true;
}}
function hlev1_AnyClick()
{
if (Verbs.UsedAction(eGA_Push)) {
cJojo.Say("I need coordinates first.");
}
if (lev1 == true){
cJojo.Say("Engage!");
sRocket.Play();
}
else if(Verbs.UsedAction(eGA_Pull)) {
cJojo.Say("I'm already Disengaged.");
}
else if(Verbs.UsedAction(eGA_Open)) {
cJojo.Say("What would that do?");
}
else if(Verbs.UsedAction(eGA_Close)) {
cJojo.Say("What would that do?");
}
}
I'd like to mention that you may simplify conditions with boolean variables.
Because a boolean variable itself translates to "true" or "false" value, you do not need to compare them directly.
if (var == true)
may be written as if (var)
, and if (var == false)
may be written as if (!var)
.
" ! " is a NOT operator, it compares opposite value.
So, for example, you may change
if ((((but1 == true && (but2 == true) && (but3 == true) && (but4 == true))))
To
if (but1 && but2 && but3 && but4)
okay that's cool to know, but I am still lost :D
Assuming the lock's order is: 2-4-3-1, you could do something like this:
// room script file
bool but1;
bool but2;
bool but3;
bool but4;
bool lev1;
function Set4ButtonsToInitialValues()
{
but1 = false;
but2 = false;
but3 = false;
but4 = false;
}
function room_Load()
{
Set4ButtonsToInitialValues();
}
function hbut1_AnyClick()
{
if (lev1) cJojo.Say("Coordinates are already ready");
else if (!but1 && but2 && but3 && but4)
{
sClick.Play();
but1 = true;
if (lev1 == false)
{
cJojo.Say("Coordinates ready");
lev1 = true;
}
}
else Set4ButtonsToInitialValues();
}
function hbut2_AnyClick()
{
if (!but1 && !but2 && !but3 && !but4)
{
sClick.Play();
but2 = true;
}
else Set4ButtonsToInitialValues();
}
function hbut3_AnyClick()
{
if (!but1 && but2 && !but3 && but4)
{
sClick.Play();
but3 = true;
}
else Set4ButtonsToInitialValues();
}
function hbut4_AnyClick()
{
if (!but1 && but2 && !but3 && !but4)
{
sClick.Play();
but4 = true;
}
else Set4ButtonsToInitialValues();
}
function hlev1_AnyClick()
{
if (!lev1)
{
if (Verbs.UsedAction(eGA_Push)) cJojo.Say("I need coordinates first.");
else if(Verbs.UsedAction(eGA_Pull)) cJojo.Say("I'm already Disengaged.");
else if(Verbs.UsedAction(eGA_Open)) cJojo.Say("What would that do?");
else if(Verbs.UsedAction(eGA_Close)) cJojo.Say("What would that do?");
}
else if (lev1)
{
cJojo.Say("Engage!");
sRocket.Play();
}
}
that worked great. even though I cannot comprehend some of it. My brain just cant follow the logical path of why its working. anyway. Now when I Pull ,push,open, the lever it says engage on all instances. Not a huge deal. Thanks for your help!
Yes, I didn't know for sure what you meant with these actions.
Maybe this would improve it, just replace the function 'hlev1_AnyClick' with this:
function hlev1_AnyClick()
{
//in case the player has not solved the lock code sequence:
if (!lev1) cJojo.Say("I need coordinates first.");
//but, in case the player has solved the lock code sequence:
else if (lev1) //if code sequence is correct:
{
if (Verbs.UsedAction(eGA_Pull)) cJojo.Say("I'm already Disengaged.");
else if (Verbs.UsedAction(eGA_Open)) cJojo.Say("What would that do?");
else if (Verbs.UsedAction(eGA_Close)) cJojo.Say("What would that do?");
else if (Verbs.UsedAction(eGA_Push))
{
sRocket.Play();
cJojo.Say("Engage!");
}
}
}
perfect! I am slowly understanding. thanks so much!
Good to see it works :)