Point and Click Sample Project

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Point and Click Sample Project

#1 Post by SusanTheCat » Sat Apr 20, 2013 8:39 pm

This is a simple game to demonstrate:
- the use of an inventory screen that uses Screen Language per KimiYoriBaka (see http://lemmasoft.renai.us/forums/viewto ... =8&t=12849)
- the use of Screen Language to create a point and click style puzzle.

Image


Each room gets its own screen that looks like this:

Code: Select all

screen outside_room: 
    on "hide" action Hide("displayTextScreen")
    if iFirewood not in inventory and not fireplace_wood:
        add "outside_wood.jpg"
        imagebutton:
            xpos 370
            ypos 462
            xanchor 0.5
            yanchor 0.5
            idle "empty.png"
            hover "yellow.png"
            action [Hide("displayTextScreen"),addItem(iFirewood)]
            hovered Show("displayTextScreen", displayText = "Someone left some wood here.") 
            unhovered Hide("displayTextScreen")
    else:
        add "outside.jpg"
       
    imagebutton:
            xanchor 0.5
            yanchor 0.5
            xpos 650
            ypos 322
            idle "empty.png"
            hover "yellow.png"
            action Jump("kitchen")
            hovered Show("displayTextScreen", displayText = "Go to Kitchen.") 
            unhovered Hide("displayTextScreen")     
Image

Something I did was change the whole background when someone picked something up. That's because I was being lazy and just using the 3d renders. :)

The fish was done differently:

Code: Select all

    if iFish not in inventory:
        add "herring.png" xpos 500 ypos 160 xanchor 0.5 yanchor 0.5
        imagebutton:
            xanchor 0.5
            yanchor 0.5
            xpos 500
            ypos 160
            idle "empty.png"
            hover "yellow.png"
            action [Hide("displayTextScreen"),addItem(iFish)]
            hovered Show("displayTextScreen", displayText = "Someone left this fish out.") 
            unhovered Hide("displayTextScreen")
I could have just used the fish image for the imagebutton, but I wanted to stay consistent with the yellow circle.

Items are defined like this:
Item(name,imagename)
Example:

Code: Select all

    iMatch = Item("Match","match.png")
    iFirewood = Item("Firewood","wood.png")
    iFish = Item("Fish","herring_item.png")
I made a couple of Screen Actions to help me out.

addItem: Action that adds the item to the player's inventory
addItem(item)
example:

Code: Select all

    if iFish not in inventory:
        imagebutton:
            idle "herring.png"
            hover "herring_hover.png"
            action addItem(iFish)
testItem: Action that will test to see if the selected item is a certain item, then change a variable, then optionally remove the item
testItem(item,variable, value, remove)

Code: Select all

        imagebutton:
            idle "empty.png"
            hover "yellow.png"
            action testItem(iFirewood,"fireplace_wood", True, True)
That test to see if the iFirewood item is selected. If it is, then fireplace_wood is set to True and the item is removed from inventory.

I think it is pretty self explanatory; but then again, I wrote it. :) Now to see if it works on Android.

Susan
Download the attached file (PointandClickTest.zip) and unzip it into your Ren'py Files directory to see the code.
Attachments
Point and Click Test-1.0-all.zip
This is the distribution file if you just want to play it.
(20.93 MiB) Downloaded 838 times
PointandClickTest.zip
(1.12 MiB) Downloaded 692 times
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Point and Click Sample Project

#2 Post by KimiYoriBaka » Sun Apr 21, 2013 5:46 pm

it's interesting that you posted this just as I was considering whether to post code for changing the mouse cursor at any time (which I just got working a couple days ago).

a few criticisms:

--it'd be better to put the text describing the objects at the bottom or top of the screen so that it doesn't get in the way of everything else.

--it's really not a good idea to have the player click arbitrary spots to change locations.

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Point and Click Sample Project

#3 Post by SusanTheCat » Sun Apr 21, 2013 10:32 pm

KimiYoriBaka wrote:it's interesting that you posted this just as I was considering whether to post code for changing the mouse cursor at any time (which I just got working a couple days ago).


That would be cool.
KimiYoriBaka wrote: a few criticisms:

--it'd be better to put the text describing the objects at the bottom or top of the screen so that it doesn't get in the way of everything else.

--it's really not a good idea to have the player click arbitrary spots to change locations.
I was debating whether the text would be better in the one location, or if near the cursor like a tooltip would be better.

About the changing location hotspots, I put those in at the last minute. Previously I was using menu items. In an actual game, would it be better to have exits in the graphic (such as the doors) just by themselves; or also have arrows that indicate movement?

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Point and Click Sample Project

#4 Post by KimiYoriBaka » Mon Apr 22, 2013 7:51 pm

In an actual game, would it be better to have exits in the graphic (such as the doors) just by themselves; or also have arrows that indicate movement?
depends on the game's atmosphere. in this case, either would work as long as the player doesn't have to search for them

Timberduck
Regular
Posts: 59
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: Point and Click Sample Project

#5 Post by Timberduck » Wed Jan 22, 2014 5:27 pm

This is really awesome.

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Point and Click Sample Project

#6 Post by SusanTheCat » Mon Feb 10, 2014 9:29 am

To see a bigger example that has other puzzles go here:
http://lemmasoft.renai.us/forums/viewto ... 11&t=21101

The source code is included with the game for stealing learning purposes.

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
shortycake
Regular
Posts: 118
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Point and Click Sample Project

#7 Post by shortycake » Thu Dec 04, 2014 2:41 am

Hello, I'm sorry to bother but I'm trying to use this code but I'm always having problem when it comes to 'testItem' code..?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 155, in script
  File "renpy/common/000statements.rpy", line 447, in python
  File "game/script.rpy", line 35, in python
AttributeError: 'StoreModule' object has no attribute 'active_item'

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

Full traceback:
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\execution.py", line 294, in run
    node.execute()
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\ast.py", line 1595, in execute
    self.call("execute")
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\ast.py", line 1613, in call
    renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\statements.py", line 144, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 447, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\exports.py", line 2095, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\ui.py", line 237, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\core.py", line 2048, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\core.py", line 2635, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\layout.py", line 761, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\layout.py", line 761, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\layout.py", line 761, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\screen.py", line 323, in event
    rv = self.child.event(ev, x, y, st)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\layout.py", line 761, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\behavior.py", line 690, in event
    return handle_click(self.clicked)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\behavior.py", line 633, in handle_click
    rv = run(action)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\behavior.py", line 231, in run
    new_rv = run(i, *args, **kwargs)
  File "C:\Documents and Settings\emy\Desktop\renpy-6.17.4-sdk\renpy\display\behavior.py", line 238, in run
    return var(*args, **kwargs)
  File "game/script.rpy", line 35, in __call__
    if store.active_item != None and store.active_item == self.item:
AttributeError: 'StoreModule' object has no attribute 'active_item'

Windows-XP-5.1.2600-SP3
Ren'Py 6.17.4.409
trial 0.0
It only happen when the spot is clicked without the selected item. (when it supposed to be ignored??)
I just want to know what is wrong and how to fix it but I'm so noob when it comes to coding ; u ;
also I'm using Ren'Py 6.17.4.409 (but planning to use the newer version; 6.18.3)

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Point and Click Sample Project

#8 Post by SusanTheCat » Thu Dec 04, 2014 10:28 am

Unfortunately I am current in a chemotherapy induced brain fog and am unable to help.

Could someone else could look into this?

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
DragoonHP
Miko-Class Veteran
Posts: 735
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Point and Click Sample Project

#9 Post by DragoonHP » Thu Dec 04, 2014 11:43 pm

shortycake: Just tested it and it works for me on 6.18.3. Are you testing it on your own project or are you playing the sample game?

SusanTheCat: I hope you get well soon.

User avatar
shortycake
Regular
Posts: 118
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Point and Click Sample Project

#10 Post by shortycake » Fri Dec 05, 2014 11:07 am

SusanTheCat: Oh, I'm so sorry for bothering you, I hope you'll get better soon.

DragoonHP: Hi. Thank you for replying to me. Yes, I'm testing it in my own project (new project) and in sample game it works perfectly fine. I tried to copy-paste them all into a new project and it works fine as long I don't edit much the script DX
Last edited by shortycake on Fri Dec 05, 2014 12:13 pm, edited 1 time in total.

User avatar
DragoonHP
Miko-Class Veteran
Posts: 735
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Point and Click Sample Project

#11 Post by DragoonHP » Fri Dec 05, 2014 11:21 am

It looks like you are forgetting something in the code. The error means that there is no variable named active_item.

Can you share the code if you don't mind? (Also, is there a line "$ active_state = None" under label start)

User avatar
shortycake
Regular
Posts: 118
Joined: Mon Jan 20, 2014 5:53 am
Completed: Night in the Cottage
Projects: The Mishka Effect, Nocturnal Affair, Lethe, Alice in Neverland
Deviantart: shortpencil
itch: shortycake
Location: Philippines
Contact:

Re: Point and Click Sample Project

#12 Post by shortycake » Fri Dec 05, 2014 12:11 pm

Ohhhhh *face palm* now I know what does that error means XD
ah it works now [so embarrass] thank you very much for helping me! Image

Post Reply

Who is online

Users browsing this forum: No registered users