• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

Need help with locking articles In-Game Wiki

Alvidas

Newbie
Jul 2, 2018
35
15
1) I followed the Tom's "In-Game Wiki-Like Glossary" on Patreon, ( ) and everything is working fine except the last part, the ability to lock articles (links) in the WIKI. That presents a problem, as I don't want the player to see certain things in the beginning of the game.
I created a separate wiki.rpy with the entries and the Pyton locking code from the Patreon example, but that has absolutely no effect, the wiki is available from the beginning. Probably I am doing something wrong but I don't know what...
Anyone is familiar with this and can help?

2) I wonder if I disable the wiki navigation button in screens.rpy, can it be called by code and enabled later at a certain stage in the game?
 
  • Like
Reactions: Palanto

Palanto

Active Member
Game Developer
Oct 4, 2017
964
1,839
1) I followed the Tom's "In-Game Wiki-Like Glossary" on Patreon, ( ) and everything is working fine except the last part, the ability to lock articles (links) in the WIKI. That presents a problem, as I don't want the player to see certain things in the beginning of the game.
I created a separate wiki.rpy with the entries and the Pyton locking code from the Patreon example, but that has absolutely no effect, the wiki is available from the beginning. Probably I am doing something wrong but I don't know what...
Anyone is familiar with this and can help?

2) I wonder if I disable the wiki navigation button in screens.rpy, can it be called by code and enabled later at a certain stage in the game?
Ok "your" code would be nice to see, so we can really help. But I'm almost certain that you just added all the pages to the:
Code:
default persistent.wiki_unlocked = { "wiki_index" }
part.
So of course it would show all pages right from the start, since it will show all pages stored in this set.
If you want to start with an empty set you'd create the set like this:
Code:
default persistent.wiki_unlocked = Set()
to add new pages to the "unlocked" list just:
Code:
persistent.wiki_unlocked.add( "wiki_index", "wiki_page01")
and so on and so forth, so for each page unlocked you can "add" one string to the set.


If you don't want the menu button to show, just add an if statement before the button itself.
i.e.:
Code:
if "wiki_index" in persistent.wiki_unlocked:
    textbutton _("Wiki") action ShowMenu("wiki_index")
With this bit it would only show the button if "wiki_index" has been added to the set in persistent.wiki_unlocked ;)
You could also just create a new variable for that to turn it on or off without influencing the pages.

Code:
default wiki_on = False
screens.rpy
Code:
if wiki_on:
    textbutton _("Wiki") action ShowMenu("wiki_index")
 

Alvidas

Newbie
Jul 2, 2018
35
15
@Palanto: You are 100% right!
I inserted all the pages in
Code:
 default persistent.wiki_unlocked = { "wiki_index" }
I was trying to follow the Patreon's page info, so is no modified code, just the one from the page with some extra content, this is why I didn't post it.
And I much appreciate your information regarding the way I should enter the pages, and regarding the wiki button. I will work on the modification.
Thank you!
 
  • Like
Reactions: Palanto

Palanto

Active Member
Game Developer
Oct 4, 2017
964
1,839
You're welcome ;) Just remember, everything inside the "persistent.wiki_unlocked" set will be unlocked inside the wiki ;) A set is a kind of special list object that you might want to check up on i.e. or just google "Python Set" ;)

Programiz said:
What is a set in Python?
A set is an unordered collection of items. Every element is unique (no duplicates) and must be immutable (which cannot be changed).

However, the set itself is mutable. We can add or remove items from it.

Sets can be used to perform mathematical set operations like union, intersection, symmetric difference etc.
Have fun fiddling around ;) If you encounter any more problems just let us know :)
 
  • Like
Reactions: Alvidas

Alvidas

Newbie
Jul 2, 2018
35
15
I appreciate the set() information, thanks for the link. I apologize for the late post, I spent the weekend trying to figure things out so I can ask the right questions so I don't waste other people's time..
Regarding my wiki test, I made a new short project based on the patreon code and yours to underline the things that are working and the things that are not working, probably due to my distinguished lack of knowledge...
Code:
#default persistent.wiki_unlocked = { "wiki_index" } ## replaced with empty set as per instructions.
default persistent.wiki_unlocked = Set()
default wiki_on = False
define config.hyperlink_protocol = "showmenu"
define progress = ()

label start:

  


    $ progress = 0
    "For the sake of my sanity, entries for wiki were added in script.rpy and I am using a small example from Patreon's page."
    "..."
    "I have %(progress)d  progress points.When I have 3 points, I want to activate some links."
    "{a=wiki_hamilton}Alexander Hamilton{/a} link is locked."
    "Let's check that one: {a=wiki_index}wiki index{/a}. Link is already active but not showing in the menu."
    "...I want to have Burr's entry unlocked in wiki later on, not now, so probably I made a mistake. Link is {a=wiki_burr}Burr, Aaron{/a} active already."
    "..."
    $ progress += 3
    "Now I have %(progress)d  progress points."


   
label burr:
    if progress >= 2:
        "Really...Now I have %(progress)d  progress points."   
        "Entry Burr & Index are already unlocked, from the start."
        "So I gues 'init python'take precedence"
        "Bye"
        init python:
           
            persistent.wiki_unlocked.add( "wiki_index")
            persistent.wiki_unlocked.add( "wiki_burr")
            #persistent.wiki_unlocked.add( "wiki_index", "wiki_burr") ##gives error: 'add() takes exactly one argument, (2 given)'
            #persistent.wiki_unlocked.add( "wiki_index", "wiki_hamilton") ##gives error: 'add() takes exactly one argument, (2 given)'
           
            #in screens.rpy:....................
            #if wiki_on:
            #textbutton _("Wiki") action ShowMenu("wiki_index") # code not showing wiki buton.....................
    #else:
        #jump why
return
#:::::::





#label why:
    #"I wonder why?"
#return


#_-_-_-_-links-_-_-_-_

screen wiki_weehawken():

    tag menu

    use game_menu(_("Weehawken, New Jersey")):

        text _p("""
            Among other things, Weehawken was the side of the Weehawken dueling grounds,
            where duels were fought from the 1700s to the 1840s. For example, this is where
            {a=showmenu:wiki_burr}Aaron Burr{/a} shot {a=showmenu:wiki_hamilton}Alexander Hamilton{/a}.

            {a=showmenu:wiki_index}Back to Index{/a}
            """)


screen wiki_hamilton():

    tag menu

    use game_menu(_("Alexander Hamilton")):

        text _p("""
            Alexander Hamilton was a Patriot and the first treasury secretary of
            the United States. He was killed in a duel with {a=wiki_burr}Aaron Burr{/a}
            in {a=wiki_weehawken}Weehawken, New Jersey{/a}.

            {a=wiki_index}Back to Index{/a}
            """)


screen wiki_burr():

    tag menu

    use game_menu(_("Aaron Burr")):

        text _p("""
            Aaron Burr was the third Vice President of the United States. But all anyone
            remembers him for nowadays is shooting {a=wiki_hamilton}Alexander Hamilton{/a}.

            {a=wiki_index}Back to Index{/a}
            """)

screen wiki_index():

    tag menu

    use game_menu(_("Wiki Index")):

        vbox:
            text _p("""
            • {a=wiki_burr}Burr, Aaron{/a}{p}
            • {a=wiki_hamilton}Hamilton, Alexander{/a}{p}
            • {a=wiki_weehawken}Weehawken, New Jersey{/a}{p}
            """)


#default persistent.wiki_locked = { "wiki_burr" }
#:::::::
init python:

    def locked_handler(target):
        renpy.run(ShowMenu(target))

    def locked_sensitive(target):
        return target in persistent.wiki_unlocked

    config.hyperlink_handlers["locked"] = locked_handler
    config.hyperlink_sensitive["locked"] = locked_sensitive

define config.hyperlink_protocol = "locked"
define gui.hyperlink_text_insensitive_color = gui.insensitive_color
#:::::::
#define config.hyperlink_protocol = "showmenu" ##inserted here, unlocks all entries from the start.

#default persistent.wiki_unlocked.add = ( "wiki_index", "wiki_burr").....................................what is this doing?
#return
I tried to comment the things that were done and what I wanted to do but I could not figure it out. The code you indicate should be put in screens.pry was added but the reverse of wiki_index button to visible was not accomplished. There are things that I suspect are wrong with the way add() links are done that cause problems, but that is above my understanding.
And will add one more question. #default wiki_on = False works... is it possible to call it to reverse later in game? wiki_on = True? I could not make it work in reverse...
If you can take a look and make corrections so it works, I would appreciate.
 
  • Like
Reactions: Palanto

Palanto

Active Member
Game Developer
Oct 4, 2017
964
1,839
Alright, yes sorry Set only takes one string at a time with the add function. Didn't test that before but that's actually not the problem here. If you really want to do it like that (wiki button disabled at first and then enabled later) you can start with a Set that has the two entrys activated already. Since noone can enter the wiki before you enable it, and if you do so you probably already want those 2 entrys enabled. You can then add more entrys later on in the game through the add function.

Ok the "real" and only problem here is your implementation of the button.
Your original screens.rpy:
Code:
#in screens.rpy:....................
           #if wiki_on:
           #textbutton _("Wiki") action ShowMenu("wiki_index") # code not showing wiki buton.....................
   #else:
       #jump why
Ok first of all, count the spaces, including the "#" you've got 12 spaces until you hit the "if". Python takes 4 spaces as a tab.
So it's indented by 3 tabs (12spaces) now the next line has to be indented additionally 4 spaces (4 tabs from left) else it won't be inside the "if" statement.
Code:
            if wiki_on:
                textbutton _("Wiki") action ShowMenu("wiki_index")
            else:
                textbutton _("Why") action Jump("why")
Next is the question you asked, of course you can enable wiki_on later on in the game, by just using the following line:
Code:
$ wiki_on = True
Or in a python block (if you want to set more variables to something else than just wiki_on)
Code:
python:
    example_variable +=2
    example_variable2 = "Yes, that's right!"
    wiki_on = True
Python is case sensitive AND indentation sensitive. So make sure you're always on the right indentation (no tabs, just 4 spaces per indentation) and write the variable names exactly as they were written when you defined them (default nAmE = "bla" -> nAmE = "blup" if you'd write nAME it would create a new variable)
Best way to get it right is to use a good editor, like Atom or whatever you like ;)
 
  • Like
Reactions: Alvidas

Alvidas

Newbie
Jul 2, 2018
35
15
Thanks for the solution with True/False, I will implement that asap, because is working OK.
Regarding the screens code, I made a mistake when I did copy/paste the code in here, the actual look is indented, but probably I miss something else cause the code still does not enable the link later on. Here it is, and thank you for all your help ;)

Code:
################################################################################
## Main and Game Menu Screens
################################################################################

## Navigation screen ###########################################################
##
## This screen is included in the main and game menus, and provides navigation
## to other menus, and to start the game.

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Preferences") action ShowMenu("preferences")

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()
            
        
        if wiki_on:
            textbutton _("Wiki") action ShowMenu("wiki_index") #not showing wiki buton.....................

        textbutton _("About") action ShowMenu("about")
 
  • Like
Reactions: Palanto

Palanto

Active Member
Game Developer
Oct 4, 2017
964
1,839
Thanks for the solution with True/False, I will implement that asap, because is working OK.
Regarding the screens code, I made a mistake when I did copy/paste the code in here, the actual look is indented, but probably I miss something else cause the code still does not enable the link later on. Here it is, and thank you for all your help ;)

Code:
################################################################################
## Main and Game Menu Screens
################################################################################

## Navigation screen ###########################################################
##
## This screen is included in the main and game menus, and provides navigation
## to other menus, and to start the game.

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Preferences") action ShowMenu("preferences")

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()
           
       
        if wiki_on:
            textbutton _("Wiki") action ShowMenu("wiki_index") #not showing wiki buton.....................

        textbutton _("About") action ShowMenu("about")
just tested it in my own game... implemented the button the same way you did but instead of opening the wiki it would open this page....

Alright, start up your game. Inside the main menu press "Shift+O" then type:
Code:
wiki_on = True
Now you should see the button
 

Alvidas

Newbie
Jul 2, 2018
35
15
I don't believe giving the player access to developer tolls is the solution in this case.