[Solved]Help with code, please.

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
bonnie_641
Regular
Posts: 133
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

[Solved]Help with code, please.

#1 Post by bonnie_641 »

Hi!
It is the first time I try to program a game on Renpy and, although I read the documentation, I would like to know how to improve the performance. :oops:

I don't know how to optimize the speed of the character when it crosses the screen.
Are there equivalent expressions of this code but in python language?

Code: Select all

# You can place the script of your game in this file.
init:
    image man = "man.png"


# Keymap 
    python hide:
         def overlay():
             ui.keymap(K_LEFT=renpy.curried_call_in_new_context("left"))

         config.overlay_functions.append(overlay)
         
         def overlay():
             ui.keymap(K_RIGHT=renpy.curried_call_in_new_context("right"))

         config.overlay_functions.append(overlay)
         
         def overlay():
             ui.keymap(K_UP=renpy.curried_call_in_new_context("up"))

         config.overlay_functions.append(overlay)
         def overlay():
             ui.keymap(K_DOWN=renpy.curried_call_in_new_context("down"))

         config.overlay_functions.append(overlay)


# The game starts here.
label start:
   
    $ leftpressed = False
    $ rightpressed = False
    $ uppressed = False
    $ downpressed = False
    
    $ distance_x = 0
    $ distance_y = 0
    
        
    scene caff
    "Movement: Up, down, left, right"
  
       
    label loop:
        show man at Position(xpos = distance_x, ypos = distance_y + 20)
        
        

        if leftpressed:
            if distance_x > 0:
                $ distance_x -= 10

        if rightpressed:
            if distance_x < 650:
                $ distance_x += 10

        if downpressed:
            if distance_y < 650:
                $ distance_y += 10

        if uppressed:
            if distance_y > 0:
                $ distance_y -= 10
        
        $ renpy.pause(0.0000001)
        
        while distance_x == 650 and distance_y == 650:
            e "coordinate: (X=650, y=650)"
            jump loop

        jump loop
        
        
    label left:
        $ leftpressed = True
        $ rightpressed = False
        $ uppressed = False
        $ downpressed = False
        return
        
       
    label right:
        $ rightpressed = True
        $ leftpressed = False
        $ uppressed = False
        $ downpressed = False
        return
        
    label up:
        $ uppressed = True
        $ leftpressed = False
        $ rightpressed = False
        $ downpressed = False
        return
        
    label down:
        $ downpressed = True
        $ leftpressed = False
        $ rightpressed = False
        $ uppressed = False
        return
PD: Sorry for my level of English. My native language is Spanish.
PD2: The character does not stop when I stop pressing one of the buttons
Last edited by bonnie_641 on Mon Jan 15, 2018 7:35 pm, edited 1 time in total.
I speak and write in Spanish. I use an English-Spanish translator to express myself in this forum. If I make any mistakes, please forgive me.
I try my best to give an answer according to your question. :wink:

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Help with code, please.

#2 Post by xavimat »

If it's your first time with Ren'Py, probably you should start with some more simple.

I'm not sure if I fully understand your code, but I think that your code never says that "not pressing" = "stopping".

The key press decides which variable is True, and the other are False. But not-pressing does not change anything, so the variable that is True continues to be True in every cycle of the loop, so there is no reason to stop.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
bonnie_641
Regular
Posts: 133
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Help with code, please.

#3 Post by bonnie_641 »

Thank you for reply.

I understand the code: the character can moving in 4 directions (up, down, left and right) and if it arrives at coordenate execute an action (for example a message)

EDIT:
The problems are:
1. The image don't stop when I release the button.
Is it correct if I write it that way?
If I do not press the left button ... nothing happens.

Code: Select all

if leftpressed == False:
	$ distance_x = 0
2. The character are moving very slow. (Is there some alternative (in python or pygame, UDD, etc.?)


It's possible that my nivel of English cause misunderstanding. I apologize for that.
I speak and write in Spanish. I use an English-Spanish translator to express myself in this forum. If I make any mistakes, please forgive me.
I try my best to give an answer according to your question. :wink:

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Help with code, please.

#4 Post by xavimat »

I would suggest a different approach. I hope to be useful:

Code: Select all

default manx = 100
default many = 100

label start:
    scene black

    menu:
        "Option 1":
            jump option1
        "Option 2":
            jump option2

label option1:
    call screen moving1
    return

label option2:
    show text "X":
        linear 0.1 xpos manx ypos many
    call screen moving2
    $ r = _return
    $ manx = r[0]
    $ many = r[1]

    if (manx, many) == (150, 150):
        "Coordinates (150, 150)!!"
        return

    jump option2

screen moving1():
    text "X" pos (manx, many)
    key "K_LEFT" action SetVariable("manx", manx-10)
    key "repeat_K_LEFT" action SetVariable("manx", manx-10)
    key "K_RIGHT" action SetVariable("manx", manx+10)
    key "repeat_K_RIGHT" action SetVariable("manx", manx+10)
    key "K_UP" action SetVariable("many", many-10)
    key "repeat_K_UP" action SetVariable("many", many-10)
    key "K_DOWN" action SetVariable("many", many+10)
    key "repeat_K_DOWN" action SetVariable("many", many+10)
    textbutton "Close" action Return()

screen moving2():
    text "[manx], [many]"
    key "K_LEFT" action Return([manx-10, many])
    key "K_RIGHT" action Return([manx+10, many])
    key "K_UP" action Return([manx, many-10])
    key "K_DOWN" action Return([manx, many+10])
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
bonnie_641
Regular
Posts: 133
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Help with code, please.

#5 Post by bonnie_641 »

Thank you very much :D :D :D The first option was what I wanted ♥ ♥ ♥
Thanks for your help.
I speak and write in Spanish. I use an English-Spanish translator to express myself in this forum. If I make any mistakes, please forgive me.
I try my best to give an answer according to your question. :wink:

Post Reply

Who is online

Users browsing this forum: Google [Bot], IaMe