AGS: How Do I Make An Phantasmagoria-Like Password-Protected Censorship Code?

Started by Will, Fri 03/08/2018 11:46:21

Previous topic - Next topic

Will

Hey Guys! New Here!

I was so Amazed at a Sierra Game, Phantasmagoria... Which is an FMV or Full-Motion Video. It also amazed me to create games like that and
the Adventure Game Studio is my choice of creating games like Phantasmagoria since it can also execute and play Videos through a simple code like this example.

Code: ags

PlayVideo ("FileName.ogv",eVideoSkipAnyKeyOrMouse, 0);
player.ChangeRoom(1);


Even though I'll always make FMV games in AGS (Since this is the only free software that could create one), I'll try my best to create Adventure Games with Pre-Drawn Graphics or Digitized Graphics (Like Mudlarks).

Anyway, What also caught my attention was from this feature of Phantasmagoria which is the Password-Protected Censorship Mode
which led players to either Censor any gory or Sensitive Details of the game or Uncensor any gory or Sensitive Details. And I want to put that in my currently developing game
but this game doesn't have any Sensitive detail. Like, I want to try to add this in my game, especially I want to put this in my GUI.

So, How Do I make an Password-Protected Censorship Code in AGS just like in Phantasmagoria? Like tell me how! :undecided:
will :)

VampireWombat

I haven't actually played Phantasmagoria, but I own it on Steam. Unfortunately it's for Windows only, so I'd have to wait to actually download it. But I did find the manual. From the description, you should be able to just have a global string variable and you just need to create part of the GUI to let you set the variable as the password. Then simply have the variable required in the future if you want to change the censor.
If you have no idea how to even start, then you should search Youtube for How to use AGS Part 38. Watch that video and 39.

Edit: You'll also need to create a 2nd global variable. If you choose int, then have it set to like 1 once the password is created. If you choose bool, set it to true at this point. And then you use this variable to determine if the player has already set a password.
And you'd need a second gui at this point which compares what's typed in to the already set password.

Hopefully this makes sense. If not, I could just make a quick game.

Will

Thanks! By the way, Where do I gonna put the global string Variable? In the GlobalScript's Header or In the Script Itself?
Hope It Works!:smiley:
will :)

dayowlron

Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

VampireWombat

I'm not completely sure what you mean by the question. There's an area for creating global variables.
Here's a screenshot from the project I made to make sure that things work as I tried to explain.


Crimson Wizard

The "Global Variables" panel is meant as a faster method of creating global variables. But you can do same in script.

To answer the question directly -
Quote from: Will on Sun 05/08/2018 11:49:02
By the way, Where do I gonna put the global string Variable? In the GlobalScript's Header or In the Script Itself?

You put variable in the script body but declare it with "import" keyword in the header to let other scripts see and use it:
Code: ags

// In GlobalScript.ash
import String MyVariable; // if you forget "import" word here, this will work as creation of duplicate variables in every other script

// In GlobalScript.asc
String MyVariable;
export MyVariable; // you need to put "export" command to 'open' this variable for other scripts.


The Global Variables panel does the same automatically, but you cannot control the visibility area of these variables (they will always be open for every other script in game), and you cannot use custom types (the structs you declared).

Will

Okay, I got the Global Variables. And I've Also Watched the tutorial Video on How to Put the Variables, GUI and Such But... How Do I Like, Say Like for Example: When the Player clicked the "On" Button on the GUI then the Another GUI will show up, Prompting the Player to Enter the Password. Like How do I make that Variable of the Player Successfully enter the Password and The Variable of the Player Fails to enter the Password.

By The Way, Can you also show me the Code on How to Make the Another GUI appear after the Player clicked "On" (For Example)... If you don't get what I'm Saying, Can you confirm if this right on making the Other GUI dissapear and the another GUI appear? Like this.

Code: ags

g1stGUI.Visible = false
g2ndGUI.Visible = true


Thanks!
will :)

VampireWombat

Removed due to being confusing.

Cassiebsg

Pardon my french, but aren't you forgetting to set a variable there to say that the password was entered correctly?  ???
There are those who believe that life here began out there...

VampireWombat

Removed due to being confusing.

Cassiebsg

I'm more confused by that code now.  8-0
CensorLevel is your global, assumed it's set to 1 by default.
What I don't get is, that seems like even if you don't set a Password, cause if PasswordSet =/= 1 it will turn the censorship off anyway.  ???

Either I'm very confused, or your code is needing some commenting to be understood.
There are those who believe that life here began out there...

VampireWombat

I'm just going to let someone else help with this.

Cassiebsg

Geez... now you forced me to go find the old code from  my game when I used a password to unlock the game...  :-[
Code: ags

// create a Text box on your GUI... for this example I'll call it tbUnlock, but you can call it whatever you like. Then click the event button and create the new function.

function tbUnlock_OnActivate(GUIControl *control) // this is created automaticly when you click the ... button on the events for for GUI text box.
{
  if (tbUnlock.Text == "Your Password")
  {
    isGameUnlocked = true; // This is a global variable of type bool set to false by default
    tbUnlock.Text=""; // clears the input text
    Display("Correct password. Enjoy your gory game!");
    gPassword.Visible = false; // closes the GUI that you are using for the password entry
  }
  else 
  {
  tbUnlock.Text=""; // clear text
  Display("Wrong password!");
  }
}


Hope I haven't forgotten anything.
Keep in mind that the password will have to be entered everytime the player starts a new game, but it will remember that it's unlocked when loading a saved game.

Was this what you needed?

EDIT: Also, when in your game you then wish to check if you should display a censored version or a none censured, all you need to do is
Code: ags

if (isGameUnlocked) 
  {
    //  Add your gory code her
  }
else
  {
    //  Add your censured code her
  }
There are those who believe that life here began out there...

Will

Thanks Cassiebsg, but what I want to set the "Password Variable" or the Password itself is NOT when the Player enters at Start, but in the Options. Like, when the Player opens the Options GUI, There is a function called the "Censorship mode", When the Player clicked the button "ON", the Game will Prompt the Player to enter the Password and if successful, It will Unlock either Gory, Mature or Sensitive detail of the Game. Clicking "OFF" will turn off Censorship Mode, which now returns to the Censored Details of the Game.

Thanks BTW!
will :)

VampireWombat

Okay, maybe I can explain my code enough today to help.

First, I created the variables which I posted a screenshot of earlier.



Then I created a gui called gCreatePassword. This gui has a text box named tbCreatePw for entering the password to create one. And is has an okay button named btnCreatePwOk which processes the information. Code for the button.
Code: ags
function btnCreatePwOk_OnClick(GUIControl *control, MouseButton button)
{
  CensorPassword = tbCreatePw.Text; // sets the password variable to what was entered in the text box
 gCreatePassword.Visible = false; // makes the gui go away
 Display ("Your password is %s.",CensorPassword ); // just verifies what password you made. You can remove this line.
 PasswordSet = 1; // changes the variable to show that a password was created. I used int instead of bool in case a 3rd option might come up.
}


Then I created a 2nd gui with 3 levels of censoring.
No violence button.
Code: ags
function btnNoViolence_OnClick(GUIControl *control, MouseButton button)
{
CensorLevel = 2; // means the most censoring. Doesn't require a password to change to this.
Display ("Your game is now set to no violence");
}

Medium violence button
Code: ags


function btnMild_OnClick(GUIControl *control, MouseButton button)
{
  if (PasswordSet == 1) // checks if a password is set
  {
  if (TypedPassword == CensorPassword) // verifies the password is correct
  {
CensorLevel = 1; // sets the game to medium censoring.
Display ("Your game is now set to minimal violence");
  }
 else
  {
  gEnterPassword.Visible = true; // opens the gui for entering the password
  }
  }
 else // This area is for setting the censoring if there is no password created.
  {
CensorLevel = 1; // sets the game to medium censoring. 
Display ("Your game is now set to mild violence");
  }
}


Full violence button
Code: ags
function btnFull_OnClick(GUIControl *control, MouseButton button)
{
  if (PasswordSet == 1) // checks if a password is set
  {
  if (TypedPassword == CensorPassword) // verifies the password is correct
  {
CensorLevel = 0; // sets the game to no censoring.
Display ("Your game is now set to full violence");
  }
 else
  {
  gEnterPassword.Visible = true; // opens the gui for entering the password
  }
  }
 else // This area is for setting the censoring if there is no password created.
  {
CensorLevel = 0; // sets the game to no censoring.
Display ("Your game is now set to full violence");
  }
}


Okay button
Code: ags
function btnCensorOk_OnClick(GUIControl *control, MouseButton button)
{
gCensorLevel.Visible = false; // makes the gui go away
}


And then I created a gui for entering the password.
It has a text box and an okay button.
Code for the okay button
Code: ags
function btnCreatePwOk_OnClick(GUIControl *control, MouseButton button)
{
  CensorPassword = tbCreatePw.Text; // sets the password variable to what was entered in the text box
 gCreatePassword.Visible = false; // makes the gui go away
 Display ("Your password is %s.",CensorPassword ); // just verifies what password you made. You can remove this line.
 PasswordSet = 1; // changes the variable to show that a password was created. I used int instead of bool in case a 3rd option might come up.
}

function btnEnterPwOk_OnClick(GUIControl *control, MouseButton button)
{
  TypedPassword = tbEnterPw.Text; // puts the password that was typed into the text box into the string variable
  if (TypedPassword == CensorPassword) // verifies the password is correct
  {
  gEnterPassword.Visible= false; // makes the gui go away
 
  }
 else // what happens when the password is wrong
  {
 Display ("Wrong password.");
   gEnterPassword.Visible= false; // makes the gui go away
  }
}


And this is code I used on a tv in the test game to make sure the censoring worked.

Code: ags
function hTeeVee_Interact()
{
  if (CensorLevel == 0) // what happens if there's no censoring
  {
player.Say("Wow, corpses everywhere.");
 
  }
 else if (CensorLevel == 1) // what happens if there's medium censoring
  {
player.Say("Huh, no blood when his head was cut off.");
 
  }
 else // what happens when there's full censoring.
  {
player.Say("Aww. They're hugging each other."); 
  }
}


I hope I didn't miss anything and that it all makes sense now.




Cassiebsg

@Will, that is exactly what the code does. You just have to put the text box in your options settings.
What I meant by "start" is that if you close the game (Quit/Exit) and re-open it (double click the icon in windows to run), the game will be in default mode again.
If you had made a save game while  uncensored and load it it will be uncensored but if you start a new game then it will be censored (meaning you need to go to the options again and set the password).

If you want the game to remember that you have unlocked when you open the game again at a later time, you will need to save that info externally. Or create a "hidden" savegame just to keep that info.

"Game start" is not the same as "start a new game by clicking the button in the main menu"...  ;)

Edit: also I only made my variable to be a yes/no, and since you have more options, you''ll need another type of it, and an "else if" after the 1st if...

Or just use VW's code. Even if looks a lot more complicated to me.  (laugh)
There are those who believe that life here began out there...

VampireWombat

Mine probably is over complicated.

And in theory, isn't there a way to create a save game when the password is created and then have it autoload in the future? Of course it would mean needing to set the password at the very start of the game.

I'm currently unable to attempt making code to test it, though.

Or maybe Cassie knows how to write the password to a file and access it, since I found this.

Will

@Cassiebsg, Thanks for that Info by the way.

You also said earlier this:

QuoteIf you want the game to remember that you have unlocked when you open the game again at a later time, you will need to save that info externally. Or create a "hidden" savegame just to keep that info.

I think creating a "hidden" savegame is a best bet for that Option. But Since I'm new to AGS, I think I need to know also the Code on How to make a "hidden" Save Game.

P.S. - Also Thanks to @VampireWombat for that Code too. Maybe I'll try that one next time or some time.
will :)

Cassiebsg

Okay, a hidden savegame is just one that the user can't load from the load list. Just like the restart point uses agssave.999, you could just use the slot 998  and save the info there.

To save a game to a slot you just type:

SaveGameSlot(998, "Censorship"); // 998 is the slot you want to save to and "Censorship" is the name you wish to give the savegame file.

Then you can read/load it by using:

RestoreGameSlot(998);

You can place it on the function on_event
As in:
Code: ags

function on_event(EventType event, int data)
{
  if (event = eEventRestoreGame)
  {
     if (SavedGameslot==998)
     {
        SavedGameslot=0; // I'm not sure that seting this to 0 is needed, but I had it on my code, so I'll leave it here.
        // you can then read the info of your password setting and maybe display a message saying what level of censurship is the game now set to or what ever else you need to do
      }
  }
}


This might work well for if the player changed the settings before starting a new game, but will crap up if the player sets the option mid playing, since it will effectively also save and load all the variables that are already changed.
There might be a way to deal with that, but it's not something I know how to, since I used an external file where I wrote the state of the game (I used the internal command File.Open Read/Write)... in my case it was just unlocked. In your case you would write "Gory" or "Mature" and assume "Sensitive" if file not found.

This last option requires a bit more coding (not so much to write the file, but to read it), if you wish I can turn my work PC on and then copy past the code from my game in (or what is left and might be relevant).
There are those who believe that life here began out there...

Will

will :)

Will

Okay, This May Be A Late Reply but...

@Cassiebsg

What did you mean about this code when creating a Hidden Save Game?
Code: ags
function on_event(EventType event, int data)
{
  if (event = eEventRestoreGame)
  {
     if (SavedGameslot==998)
     {
        SavedGameslot=0; // I'm not sure that seting this to 0 is needed, but I had it on my code, so I'll leave it here.
        // you can then read the info of your password setting and maybe display a message saying what level of censurship is the game now set to or what ever else you need to do
      }
  }
}
 


Where Do I put the Hidden Save File? In the GUI of My Enter Password GUI? Please Answer...
will :)

Khris

I don't think any of this is necessary.

If somebody decided to play the game a second time from the start, months or years later, surely they are willing to spend 5 seconds entering the uncensored password again...?

Cassiebsg

@Khris: Depends exactly what he wants to do.
On my game it was meant to remember that the game was "unlocked", and if the file wasn't found or was corrupt it would then revert to default which was "locked". I ended up dropping this since it seemed to confuse my testers. (laugh) And just gave a check box on the settings instead.

@Will: Yes, you put the code (the savegame line) inside your textbox onclick function and remember to set the censorship variable to the correct one.

You'll have something like:
Code: ags

function censor_OnClick() // or what ever your function it called)
{
  if (password_is_gore)
  {
    //do stuff
    censorship_variable=2; // assuming 0 is full censored, 1 is mild and 2 is full gore
    savegameslot(998, "censorship");
  }
  else if ( password_is_mild)
  {
    //do stuff
    censorship_variable=1; // assuming 0 is full censored, 1 is mild and 2 is full gore
    savegameslot(997, "censorship");
  }
  else
  {
    //do stuff
    Display("Wrong password");
  }
}

function game_start() // you should have this function already on global scripts
{
    if (Game.GetSaveSlotDescription(998)!=null) 
    {
        //set the game to uncensored mode... uhm... you want 2... maybe use 997 for one and 998 for another? Then remember to delete the one you don't want... like if full censor = delete 997 and 998, if it's in mild delete 998 and write 997, if full gore, delete 997 and write 998?
    censorship_variable=2; // assuming 0 is full censored, 1 is mild and 2 is full gore
    }
    else if  (Game.GetSaveSlotDescription(997)!=null)
    {
     // add code
    censorship_variable=1; // assuming 0 is full censored, 1 is mild and 2 is full gore
    }
}


Hope you can figure this out, this way you aren't actually loading the restore file, just checking if one or the other exist and setting the correct variable at game start.

Note: However, if you're adding this as "child protection" then you probably should not remember the censorship mode, and then all this is pointless... (roll)
There are those who believe that life here began out there...

Will

@Cassiebsg Is this okay/correct?
Code: ags
function tbPassword_OnActivate(GUIControl *control)
{
  if (tbPassword.Text == "My Password") //either whatever password I wanted
  {
    
    isGameUnlocked = true; //this is the variable that you showed me earlier before
    tbPassword.Text="";
    SaveGameSlot(998, "censored"); //the Hidden SaveGame Slot you said to me...
    Display("Password is Correct.");
  }
  else
  {
    tbPassword.Text="";
    Display("Wrong Password, Try Again!");
  }
}


That was when the Player will enter the Password in order to censor any disturbing details.

Code: ags
function btnEnter_OnClick(GUIControl *control, MouseButton button)
{
    if (Game.GetSaveSlotDescription(998)!=null) //this is when, in order to save the options and create a save file, they must press the "Enter" button, not the Enter key on the keyboard
    {
      isGameUnlocked = true;
    }
    else if (Game.GetSaveSlotDescription(997)!=null)
    {
      isGameUnlocked = false;
    }
}


Is that okay? I want to clarify if it is... If not, just tell me the right way how.
Thanks!
will :)

Cassiebsg

Yes, somewhat.

I thought you were doing 3 levels of censorship? Censored, mild and Gore? Or will you only have 2?

You might want to change the variable name from isGameUnlocked to something else that gives meaning in your code... maybe isGameCensored? I have made it an habit to start all my bools with a question... like is that way the answer gives perfect meaning and I don't need to add much more comments. ;) But feel free to name it whatever works for you.
If you only have to states: censor and non censored, you only on if (Game.GetSaveSlotDescription...

And uhm... why do you have two codes for the text box? You should set the variable to true when you save and accept the code, and to false when the password is wrong.

The if (Game.GetSaveSlotDescription check should be on function game_start(), so that it checks if the file exists or not when you launch the game and sets the variable accordingly.
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk