kimono said:
Hi kimonokimono said:Hi, I wish to create a password system that spawns an item:
In this example, the letters S, E, G, A spawns an apple.
The letters are obstacles and the ->End spawns the expected item.
Do you think there is a simple way to make passwords that spawns different items?
void main()
{//Change global variables when each computer is destroyed to unlock exit door in ST6A
void self = getlocalvar("self");
void branch = openborvariant("current_branch");
//DISABLE LOCKS FOR THE EXIT DOOR
if(branch == "sor3_st6b"){setglobalvar("st6_lock1", 1);}
if(branch == "sor3_st6c"){setglobalvar("st6_lock2", 1);}
if(branch == "sor3_st6d"){setglobalvar("st6_lock3", 1);}
if(branch == "sor3_st6e"){setglobalvar("st6_lock4", 1);}
}
if(vName == "st6_exit"){
if(getglobalvar("st6_lock1") == 1){
if(getglobalvar("st6_lock2") == 1){
if(getglobalvar("st6_lock3") == 1){
if(getglobalvar("st6_lock4") == 1){
if(vAniID == openborconstant("ANI_IDLE")){
changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
}
}
}
}
}
}
kimonokimono said:Damon Caskey: That's very clever to store the letter in memory and compare to a list of words! I like this!
I'll make a punishement for the player for a wrong or random combinaition: the player will fall in the room below where he will got some problems.
Kratus: Your method is correct, one password will spawn the exit door of the stage. If I understand correctly, some words like E, G, A, S or G, E, S, A will work too even if there are wrong?
Bloodbane: Thank you Bloodbane, that's very kind to you![]()
drawstring(50, 50, 0, getglobalvar("st6_lock1")+"_"+getglobalvar("st6_lock2")+"_"+getglobalvar("st6_lock3")+"_"+getglobalvar("st6_lock4"));
char letter = <get the letter just punched>
char working_string = getglobalvar(<working string key>);
// If we get an empty value from the global var, we
// will initialize a blank string. This ensures engine
// treats our variable as a string when adding.
if(!working_string)
{
working_string = "";
}
working_string = working_string + letter;
setglobalvar(<working string key>, working_string);
Thanks Damon Caskey, your method seems to be more clean. I will try it in SOR2X tooDamon Caskey said:You don't have to store each letter in its own variable - that just adds more complexity. This is how I would work the string:
Code:char letter = <get the letter just punched> char working_string = getglobalvar(<working string key>); // If we get an empty value from the global var, we // will initialize a blank string. This ensures engine // treats our variable as a string when adding. if(!working_string) { working_string = ""; } working_string = working_string + letter; setglobalvar(<working string key>, working_string);
That builds a single string with all the letters punched so far. If you wanted to be really efficient about it, you could assign each letter a number, add them to produce a single encoded integer value with a checksum, then compare it to static numbers to find a match. But for what you are trying to accomplish here, that isn't really necessary.
DC