[Fight] customized attacks damages depending on variables

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
ultimate-saiyajin
Newbie
Posts: 10
Joined: Sun Apr 23, 2017 8:46 am
Contact:

[Fight] customized attacks damages depending on variables

#1 Post by ultimate-saiyajin »

I just want to know if it is possible to pass a variable in the Jump of an imagebutton?

In my fight screen:

Code: Select all

imagebutton idle "images/punch.png" hover "images/punch_hover.png" xpos 1356 ypos 588 focus_mask True clicked Jump(fight.attack(20))
To jump to this label with damages in parameters:

Code: Select all

label .attack(atk):
    $ enemy.attacked(atk)

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: [Fight] customized attacks damages depending on variable

#2 Post by Evildumdum »

It's been a while since i attempted to pass variables to a label since i mostly work in functions now. Having said that, i think the correct format would be:

Code: Select all

imagebutton idle "images/punch.png" hover "images/punch_hover.png" xpos 1356 ypos 588 focus_mask True clicked Jump(fight.attack, 20)
Though i may be corrected on that at some point. Give it a try though.
"If at first you don't succeed, try hitting it with a shoe."

ultimate-saiyajin
Newbie
Posts: 10
Joined: Sun Apr 23, 2017 8:46 am
Contact:

Re: [Fight] customized attacks damages depending on variable

#3 Post by ultimate-saiyajin »

Thank you for your answer Evildumdum but I have already tried this method and it does not work. I also tried to do it with a Call but there is not statement equivalent to Call in an imagebutton.

No matter how I place my parenthesis, my points, my commas or my quotation marks, I can not pass my parameters in an imagebutton while in a label with a call it works ...

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Fight] customized attacks damages depending on variable

#4 Post by trooper6 »

Looking at the documentation, there doesn't seem to be a way to add a variable to Jump Screen Action. (https://www.renpy.org/doc/html/screen_a ... ol-actions)
Also, there is no Call screen action.
My recommendation would be to either:
a) Rather than jumping, create a Function that does all that you want, because you can pass a variable in the Function screen action
b) have a global variable and use the SetVariable screen action before you jump to the label.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

ultimate-saiyajin
Newbie
Posts: 10
Joined: Sun Apr 23, 2017 8:46 am
Contact:

Re: [Fight] customized attacks damages depending on variable

#5 Post by ultimate-saiyajin »

Thanks trooper6, this seems to work with Function when I use a function without parameters. But when I put parameters like this:

Code: Select all

imagebutton idle "images/punch.png" hover "images/punch.png" xpos 1000 ypos 588 focus_mask True clicked Function(enemy.attacked(punch.damages))
I have this error that appears : TypeError: ‘int’ object is not callable

Code: Select all

While running game code:
  File "game/script.rpy", line 380, in script call
    call fight("fight_place",player,enemy)
  File "game/fight.rpy", line 9, in script
    call screen fight_screen(player,enemy)
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "renpy/common/00action_other.rpy", line 484, in __call__
    rv = self.callable(*self.args, **self.kwargs)
TypeError: 'int' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 380, in script call
    call fight("fight_place",player,enemy)
  File "game/fight.rpy", line 9, in script
    call screen fight_screen(player,enemy)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\ast.py", line 1706, in execute
    self.call("execute")
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\ast.py", line 1724, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\statements.py", line 145, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\exports.py", line 2526, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\ui.py", line 285, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\core.py", line 2526, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\core.py", line 3204, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 960, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 960, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 960, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 651, in event
    rv = self.child.event(ev, x, y, st)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 960, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\behavior.py", line 889, in event
    return handle_click(self.clicked)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\behavior.py", line 824, in handle_click
    rv = run(action)
  File "C:\Program Files\renpy-6.99.12.4-sdk\renpy\display\behavior.py", line 306, in run
    return action(*args, **kwargs)
  File "renpy/common/00action_other.rpy", line 484, in __call__
    rv = self.callable(*self.args, **self.kwargs)
TypeError: 'int' object is not callable
Any ideas for passing parameters?

PS : I do not use the SetVariable with a Jump because I want to use ATL. This will leave the screen temporarily and the stats will no longer appear on the screen.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Fight] customized attacks damages depending on variable

#6 Post by trooper6 »

ultimate-saiyajin wrote:Thanks trooper6, this seems to work with Function when I use a function without parameters. But when I put parameters like this:

Code: Select all

imagebutton idle "images/punch.png" hover "images/punch.png" xpos 1000 ypos 588 focus_mask True clicked Function(enemy.attacked(punch.damages))
I have this error that appears : TypeError: ‘int’ object is not callable

Any ideas for passing parameters?
Well, one of the problems is that you haven't formatted your button correctly. You may want to review the imagebutton documentation.
(https://www.renpy.org/doc/html/screens.html#imagebutton)
One of the first things you'll notice is that there is no "clicked" property...rather you want "action"

Try making your button like so (I'm going to format it with a colon and a block because I think it look clearer, but you can put it all on one line if you like):

Code: Select all

imagebutton:
    idle "images/punch.png" 
    hover "images/punch.png" 
    xpos 1000 
    ypos 588 
    focus_mask True 
    action Function(enemy.attacked, punch.damages)
Also, I'm assuming that "enemy.attacked" is a function that is part of an object called "enemy" and that "punch.damages" is an int that is part of an object called "punch"--this is true correct? And that you declared these variables using default? It is hard to give you concrete advice without seeing all the relevant code. If there are errors it might be with enemy and punch.
ultimate-saiyajin wrote:PS : I do not use the SetVariable with a Jump because I want to use ATL. This will leave the screen temporarily and the stats will no longer appear on the screen.
I don't know what you mean by this. But if you can get Function to work then I suppose it doesn't matter.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

ultimate-saiyajin
Newbie
Posts: 10
Joined: Sun Apr 23, 2017 8:46 am
Contact:

Re: [Fight] customized attacks damages depending on variable

#7 Post by ultimate-saiyajin »

I agree with you it is not the documentation and I do not know why it works ... I took it on another topic I believe.

If I run this code:
Try making your button like so (I'm going to format it with a colon and a block because I think it look clearer, but you can put it all on one line if you like):

Code: Select all

imagebutton:
    idle "images/punch.png" 
    hover "images/punch.png" 
    xpos 1000 
    ypos 588 
    focus_mask True 
    action Function(enemy.attacked, punch.damages)
Ren'Py makes me leave the screen...
And that you declared these variables using default?
I'm not sure what you mean by this
Last edited by ultimate-saiyajin on Mon May 22, 2017 6:05 am, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Fight] customized attacks damages depending on variable

#8 Post by trooper6 »

ultimate-saiyajin wrote:
And that you declared these variables using default?
I'm not sure what you mean by this
Current best practices for declaring variables is to use "default" rather than declaring them in an init block.

So this:

Code: Select all

default punch = Technique("Punch", 5)
default player = Fighter("Player", 500, ([punch]))
default enemy = Fighter("Enemy", 500, ([punch]))

label start:
    "Blah blah blah"
rather than this:

Code: Select all

init python:
    punch = Technique("Punch", 5)
    player = Fighter("Player", 500, ([punch]))
    enemy = Fighter("Enemy", 500, ([punch]))
ultimate-saiyajin wrote: If I run this code:
Try making your button like so (I'm going to format it with a colon and a block because I think it look clearer, but you can put it all on one line if you like):

Code: Select all

imagebutton:
    idle "images/punch.png" 
    hover "images/punch.png" 
    xpos 1000 
    ypos 588 
    focus_mask True 
    action Function(enemy.attacked, punch.damages)
Ren'Py makes me leave the screen...
Are you perhaps calling the screen rather than showing it?

When you call a screen, it brings up the screen in its own space, waits for you to do something and then automatically returns. When you show a screen the screen stays up. If you don't want the game to progress while the screen is up, make sure to add modal True to you screen, and a button or some other means to close the screen.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

ultimate-saiyajin
Newbie
Posts: 10
Joined: Sun Apr 23, 2017 8:46 am
Contact:

Re: [Fight] customized attacks damages depending on variable

#9 Post by ultimate-saiyajin »

Current best practices for declaring variables is to use "default" rather than declaring them in an init block.
Thank you for this advice, I did not know.
Are you perhaps calling the screen rather than showing it?
Yes I used a Call. And even a call to a label that initiated the background then called the fight_screen because I did not find how to put a background in a screen. If you have a solution for that I'm interested.

I turned to Call to call my screen because when I use Show, my screen disappears as fast as it appears. I need to make a renpy.pause () so that it remains displayed …


And if I use this code:

Code: Select all

label start():
    $ renpy.show_screen("fight_screen",player,enemy)

screen fight_screen(player, enemy):
    modal True
    imagebutton:
        idle "images/button_attack.png"
        hover "images/button_attack_hover.png"
        xpos 1356
        ypos 588
        focus_mask True
        action Function(enemy.attacked,20)
If I do not put anything after show_screen and launch the game I will immediately return to the main menu. If I put dialogs after the show_screen, the screen shows but the dialogs appear on top of the screen. I would like the battle and place and the story to come back once the fight is over. Unlike the screen with Call, Function seems to work but I have the right to as many attacks (mouse clicks on the imagebutton) as there are dialogs after the show_screen.

Do you know how to update the screen with Function and how to leave the screen when I want?


Could you give me an example of Show screen with an image in parameters that will serve as a background please? It would help me a lot !

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Fight] customized attacks damages depending on variable

#10 Post by trooper6 »

Note:

Screens are not the story. They are just UI elements.

This:

Code: Select all

label start:
    show screen move()
    return

is the same thing as doing this:

Code: Select all

label start:
    return
If you give an empty block (with nothing but a screen) it is going to go back to the main menu. Instead you should work on designing your game differently so that it isn't empty.

Anyway, I suspect there are larger structural problems with your code, and in order to be able to help with it, I'd need to see more of the code. Can you post it all...or at least all the relevant parts of the code, which would be class definitions, screen definitions, function definitions, then the entire code block (or most of it) where you call your battle screen. A description of what you want to happen and what is happening instead would be helpful as well.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], AWizardWithWords, Majestic-12 [Bot], piinkpuddiin