Solved Simple password system

Question that is answered or resolved.

kimono

Well-known member
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?
 
kimono said:

kimono,

Depends on your definition of simple. It's not really that hard to do in principal, just a bit tedious to code. There's a couple of ways to do it, but for this I would add the letter to a string each time you punch one. So when they punch "S", the string is "S". If they punch "E", the string is "SE" and so on.

When the player punches "end", you just do a static check against all the possible codes, going longest to shortest. if there is a match, you stop checking and take that code's action. If no matches are found, you tell the player it's official, they suck.  ;D

It's a crude method, but not too difficult to set up and will work well for the example you posted. Just to be nice and give it some polish, I'd display the string so players can see what they have selected so far, not remove letters when you punch them, and add a "reset" that erases the string.

DC
 
kimono 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?
Hi kimono
SOR2X has this code at the stage "sor3_st6a", used by the 4 locks in the exit door, during the toxic gas countdown.
Basically each destroyed computer save a number in a variable to be read by the exit door entity. When all computers are destroyed, the exit door lock will check all variables,change your current animation and the player can get out.
GOPjdES.png


Here's the code. This script is used in the "ondeathscript" event in each computer entity's header. You can use the same system to save strings instead of saving numbers for each text entity.
Code:
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);}
}

This is the code used by the exit door entity. I'm using this at the "updateentity" script event because I have other tasks, but you can use it in other events if you want.
Code:
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"));
					}
				}
			}
		}
	}
}
 
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 :)
 
kimono 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 :)
kimono
Yes, you're right. But you can mix all passwords, read as a unic string and compare to a list of other strings.
In the example below, I converted all exit door locks to a string
QaOn4Zo.png


To mix all values to strings, you need to add any other string between them. Below I added a simple space "_" as a string. Otherwise, it will be read as a int number 1+1+1+1=4
Code:
drawstring(50, 50, 0, getglobalvar("st6_lock1")+"_"+getglobalvar("st6_lock2")+"_"+getglobalvar("st6_lock3")+"_"+getglobalvar("st6_lock4"));

From this point you can create your own string list and compare all them before spawn any entity
 
The sum of this values doesn't not take care of the letter order in this case, does it? I will make some tests.
 
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
 
Damon 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
Thanks Damon Caskey, your method seems to be more clean. I will try it in SOR2X too
 
I love the idea!
This is truely something we never saw in an openbor game (this way.)
 
Back
Top Bottom