Page 1 of 1

Point and Click Sample Project

Posted: Sat Apr 20, 2013 8:39 pm
by SusanTheCat
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.

Re: Point and Click Sample Project

Posted: Sun Apr 21, 2013 5:46 pm
by KimiYoriBaka
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.

Re: Point and Click Sample Project

Posted: Sun Apr 21, 2013 10:32 pm
by SusanTheCat
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

Re: Point and Click Sample Project

Posted: Mon Apr 22, 2013 7:51 pm
by KimiYoriBaka
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

Re: Point and Click Sample Project

Posted: Wed Jan 22, 2014 5:27 pm
by Timberduck
This is really awesome.

Re: Point and Click Sample Project

Posted: Mon Feb 10, 2014 9:29 am
by SusanTheCat
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

Re: Point and Click Sample Project

Posted: Thu Dec 04, 2014 2:41 am
by shortycake
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)

Re: Point and Click Sample Project

Posted: Thu Dec 04, 2014 10:28 am
by SusanTheCat
Unfortunately I am current in a chemotherapy induced brain fog and am unable to help.

Could someone else could look into this?

Susan

Re: Point and Click Sample Project

Posted: Thu Dec 04, 2014 11:43 pm
by DragoonHP
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.

Re: Point and Click Sample Project

Posted: Fri Dec 05, 2014 11:07 am
by shortycake
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

Re: Point and Click Sample Project

Posted: Fri Dec 05, 2014 11:21 am
by DragoonHP
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)

Re: Point and Click Sample Project

Posted: Fri Dec 05, 2014 12:11 pm
by shortycake
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

Re: Point and Click Sample Project

Posted: Fri Jun 12, 2020 11:45 pm
by Trafagal
SusanTheCat wrote:
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.
Hey Susan the Cat, I have just played your point and click, and it is such wonderful example I have been looking around for! Hope you are doing well and have recovered, or on your way to full recovery.

Thank you!

Re: Point and Click Sample Project

Posted: Fri Apr 30, 2021 8:03 pm
by mavyxdawn
Very nice tutorial! I created a tutorial in case anyone had trouble understanding the ImageButton.
Point and Click Tutorial [YouTube]