Closed-Creating a menu similar to cmd prompt with each command doing a function

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Vnigma
Regular
Posts: 50
Joined: Wed Sep 16, 2015 6:43 pm
Projects: Origin of War
Organization: VNigma
Contact:

Closed-Creating a menu similar to cmd prompt with each command doing a function

#1 Post by Vnigma »

Hello Guys,

I need some help creating a screen where the player could enter a command and each command adds up to the text of the screen, basically the screen works like this:



note that each command will add to the text just like a command prompt would do, also the screen is for hacking so it might call other screens, I want an action to be called based on the command entered, here's the code I have been using so far:

Code: Select all

screen access_menu():
    #$ initializing =0
    #$ Legend_panel = 0
    $ thiscreentext= "Initializing..."
    add im.Alpha("images/UI/item_detail_menu/Panel_bg.png",0.6)
    vbox:
        spacing 10
        add Text("Initializing...", style="access", slow_cps=20)


        if thiscreentext=="h":
            #$ thiscreentext+="\nSystem boot..."
            add Text("System boot...", style="access", slow_cps=20)
            #add Text("System boot... qqqqqqq qqqqqqqqqqqqqq qqqqqqq qqqq", style="access", slow_cps=0.)

        if Legend_panel==1:
            add Text("\n--------------------------------------------------------------------------------\nh/help\ns/scan\nc/clear\nl/load", style="access", slow_cps=20)
        #    input default "" style "access" #changed [SetVariable("Legend_panel", 1)]#, font "Fonts/techno28.ttf", color "00d5fb")
            #input id "input" style "access" #action [SetVariable("initializing",0)]
            input:
                default ""
                value VariableInputValue('thiscreentext') #This updates the note variable (defined above) with what the player enters
                length 1
                style "access"
    timer 3.0 action [SetVariable("initializing", 1)]

    timer 3.0 action [SetVariable("Legend_panel", 1)]


also how can I change the text indicator to blink just like command prompt, and I have been trying to show the text in " slow_cps=20", but it wont work when I use the timer.

Thanks in advance...
Last edited by Vnigma on Thu Jan 14, 2021 9:25 am, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Creating a menu similar to cmd prompt with each command doing a function

#2 Post by hell_oh_world »

This is how would I implement it.

Code: Select all

screen cmd():
  default inputs = []
  default input = ""
  default value = ScreenVariableInputValue("input", returnable=False)
   

  vbox:
    for ind, inp in enumerate(inputs):
      $ cmd = inp if ind == len(inputs) - 1 else ""
    
      if inp == "quit": # an if condition for your command, below is the text for it.
        text "Quitting..."
        
        if cmd == inp: # we first check if the current input in loop is the recently typed command before doing the action below for it. Do this for the rest of your conditions of different commands.
          timer 1.0 action Return()
          

      else: # the fallback if it is not recognizible.
        text "The terminal cannot recognize the command."
        
      
          
    hbox:
      spacing 5
      
      text ">>>"
      input:
        value value
      
  key "K_RETURN" action Function(inputs.append, input) # we will append the current input to the input list once enter is pressed
  
  
label start:
  call screen cmd
Havent tried but should work I guess.
for the caret you can specify the caret property of input and make your own blinking image.
https://www.renpy.org/doc/html/style_pr ... erty-caret

User avatar
Vnigma
Regular
Posts: 50
Joined: Wed Sep 16, 2015 6:43 pm
Projects: Origin of War
Organization: VNigma
Contact:

Re: Creating a menu similar to cmd prompt with each command doing a function

#3 Post by Vnigma »

Thank you, this works just fine, but how do I adjust it so that the input text clears when I press enter, also I tried adding a scrollbar:

Code: Select all

screen access_menu():
    default inputs = []
    default input = ""
    default value = ScreenVariableInputValue("input", returnable=False)
    frame:
        style_group "ingamemenus"
        background im.Alpha("images/UI/item_detail_menu/Panel_bg.png",0.6)
        side ("c r"):
            area (0,0,600,500)
            viewport id "ingamemenus3": #REMEMBER YOUR VIEWPORT ID SO THE SCROLLBAR IS PLACED FOR IT
                style_group "ingamemenus"
                draggable True mousewheel True
                #$ initializing =0
                #$ Legend_panel = 0
                #$ hackscreentext+= "."

                vbox:
                  add Text("Initializing...\nSystem Boot...", style="access", slow_cps=20)
                  for ind, inp in enumerate(inputs):
                    $ cmd = inp if ind == len(inputs) - 1 else ""

                    if inp == "quit": # an if condition for your command, below is the text for it.
                      text "Quitting..." style "access"

                      if cmd == inp: # we first check if the current input in loop is the recently typed command before doing the action below for it. Do this for the rest of your conditions of different commands.
                        timer 1.0 action Return()


                    else: # the fallback if it is not recognizible.
                      text "The terminal cannot recognize the command." style "access"



                  hbox:
                    spacing 5

                    text ">>>" style "access"
                    input:
                      #default ">>>"
                      #value value
                      style "access"

                key "K_RETURN" action [Function(inputs.append, input), SetVariable (input, "")] # we will append the current input to the input list once enter is pressedVariable("Legend_panel", 1)]

            vbar value YScrollValue("ingamemenus3"):
                style_group "ingamemenus"
                #left_bar "images/UI/vertical_hover_bar.png"
                #right_bar "images/UI/slider/vertical_idle_bar.png"
                top_bar "images/UI/slider/vertical_idle_bar.png"
                bottom_bar "images/UI/slider/vertical_idle_bar.png"
                thumb "images/UI/slider/horizontal_idle_thumb.png"
                thumb_shadow "images/UI/slider/horizontal_hover_thumb.png"
but the scroll bar doesn't seem to function properly, when the text exceeds the specified farm the scroll bar isn't draggable

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Creating a menu similar to cmd prompt with each command doing a function

#4 Post by hell_oh_world »

I think you need to actually enable the scrollbar property for the viewport https://www.renpy.org/dev-doc/html/scre ... l#viewport.
try also giving an explicit size for your viewport, and then encapsulate your vbox inside a frame and give it a yminimum of the ysize of the viewport, but don't give it an actual ysize because we want the frame to expand when more children are appended.

Code: Select all

viewport:
  mousewheel True
  draggable True
  scrollbars "vertical"
  xsize config.screen_width
  ysize config.screen_height

  frame:
    xfill True
    yminimum config.screen_height

    vbox:
      pass
And the way you clear the input looks okay to me, you just have to quote the name of the input variable, so its "input" not input and use SetScreenVariable instead of SetVariable since we're dealing with variables inside the screen. For global variables (defaulted variables outside the screen), then you can use SetVariable for that. SetLocalVariable works for variables inside the screen that starts with $. You can refer to the docs for more detailed info https://www.renpy.org/doc/html/screen_a ... ta-actions.

User avatar
Vnigma
Regular
Posts: 50
Joined: Wed Sep 16, 2015 6:43 pm
Projects: Origin of War
Organization: VNigma
Contact:

Re: Creating a menu similar to cmd prompt with each command doing a function

#5 Post by Vnigma »

It works great, but how do I customize the appearance of the scrollbars (the thumb/bar image) bear in mind I am not using gui customization.
for example this is how you costumize the vbar:

Code: Select all

vbar value YScrollValue("ingamemenus4"):
       	 	style_group "ingamemenus"
       		left_bar "images/UI/vertical_hover_bar.png"
        	right_bar "images/UI/slider/vertical_idle_bar.png"
        	top_bar "images/UI/slider/vertical_idle_bar.png"
        	bottom_bar "images/UI/slider/vertical_idle_bar.png"
        	thumb "images/UI/slider/horizontal_idle_thumb.png"
        	thumb_shadow "images/UI/slider/horizontal_hover_thumb.png"
how do I do the same for the scrollbar ?

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Creating a menu similar to cmd prompt with each command doing a function

#6 Post by hell_oh_world »

Just prefix your styles for your viewport with vscrollbar_ to target the scrollbar and since your scrollbar is set to vertical. vscrollbar_thumb, vscrollbar_base_bar etc.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]