[Solved] Adding events to a dungeon crawler.

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
ComputerArt.Club
Veteran
Posts: 409
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

[Solved] Adding events to a dungeon crawler.

#1 Post by ComputerArt.Club » Sun Jul 16, 2017 11:41 am

Hi, I am having trouble adding events to a dungeon crawler section of a game using a modified version of this code: viewtopic.php?f=51&t=19245

The dungeon crawler will play normally without any events and random battles also work, but I need to add an exit to the dungeon in addition to several event battles.

Code: Select all

    python:
#other code here... skip to the dungeon section
        # Create a dungeon stage (map,enemy)
        # "1" means wall, "0" means path. 
        stage1=Stage([
            "1111111111",
            "1111011001",
            "1000000001",
            "1110111101",
            "100a000001",
            "1111111111",
            ],
            enemy=ghost)
#outside of the dungeon section
    $ here=Coordinate(stage1,2,2,0,1)
    if [here.y][here.x]=="a":
        jump exit
The error is raised after I click through from the game's main menu (though the dungeon is called at the beginning of the story for debugging purposes)
Traceback error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 129, in script
    if [here.y][here.x]=="a":
  File "game/script.rpy", line 129, in <module>
    if [here.y][here.x]=="a":
IndexError: list index out of range

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

Full traceback:
  File "game/script.rpy", line 129, in script
    if [here.y][here.x]=="a":
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\ast.py", line 1656, in execute
    if renpy.python.py_eval(condition):
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\python.py", line 1749, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\python.py", line 1743, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 129, in <module>
    if [here.y][here.x]=="a":
IndexError: list index out of range
I have tried a few prefixes before the [here.y][here.x], but I am quite new to Renpy and couldn't see any relevant definitions in the dungeon crawler code.

I am also can't find the code for where it tells Renpy how to render the walls using the 1s and 0s. I think I will have to find this eventually as I will probably need to add a few special wall types (stairs, doors, event and story related walls... though I guess I might need to try and keep this as simple as possible if each wall needs to be rendered at several different angles).

Thanks for your time!
Last edited by ComputerArt.Club on Tue Jul 18, 2017 2:34 am, edited 1 time in total.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 659
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Adding events to a dungeon crawler.

#2 Post by Milkymalk » Sun Jul 16, 2017 12:05 pm

I can't see the __init__ of "Coordinate", but I'm making some assumptions:
if [here.y][here.x]=="a":
should probably be
if here.stage[here.y][here.x]=="a":

For me to be able to say more, I need to see the init method of "Coordinate".

The error is that [here.y][here.x] makes a list out of here.y and takes element number here.x, but since here.y is only a single element, it returns an error if here.x is larger than 0.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
ComputerArt.Club
Veteran
Posts: 409
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Adding events to a dungeon crawler.

#3 Post by ComputerArt.Club » Sun Jul 16, 2017 12:51 pm

Milkymalk wrote:I can't see the __init__ of "Coordinate", but I'm making some assumptions:
if [here.y][here.x]=="a":
should probably be
if here.stage[here.y][here.x]=="a":

For me to be able to say more, I need to see the init method of "Coordinate".

The error is that [here.y][here.x] makes a list out of here.y and takes element number here.x, but since here.y is only a single element, it returns an error if here.x is larger than 0.
Vielen Dank fuer Ihre Hilfe. Ich werde das Morgen probieren. Ich habe gesehen dass Sie in Deutschland wohnen. Mein Vater wohnt in Berlin und ich habe auch ein Deutsches Brueder. Mein Deutsch ist eigentlich nicht so gut weil ich im moment in Taiwan wohnen, aber ich dachte dass ich auf Deutsch danke sagen sollte.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 659
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Adding events to a dungeon crawler.

#4 Post by Milkymalk » Sun Jul 16, 2017 2:45 pm

:)
If there is any problem with it, post the content of Coordinate and I will see what I can do.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
ComputerArt.Club
Veteran
Posts: 409
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Adding events to a dungeon crawler.

#5 Post by ComputerArt.Club » Sun Jul 16, 2017 9:01 pm

So I changed the code to

Code: Select all

    if here.stage[here.y][here.x]=="a":
        jump exit
but I am still getting errors after the main menu.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 129, in script
    if here.stage[here.y][here.x]=="a":
  File "game/script.rpy", line 129, in <module>
    if here.stage[here.y][here.x]=="a":
TypeError: 'Stage' object does not support indexing

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

Full traceback:
  File "game/script.rpy", line 129, in script
    if here.stage[here.y][here.x]=="a":
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\ast.py", line 1656, in execute
    if renpy.python.py_eval(condition):
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\python.py", line 1749, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "E:\Renpy\renpy-6.99.12.4-sdk\renpy\python.py", line 1743, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 129, in <module>
    if here.stage[here.y][here.x]=="a":
TypeError: 'Stage' object does not support indexing
I then tried changing the code to specify stage1

Code: Select all

    if here.stage1[here.y][here.x]=="a":
        jump exit

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 129, in script
    if here.stage1[here.y][here.x]=="a":
  File "game/script.rpy", line 129, in <module>
    if here.stage1[here.y][here.x]=="a":
AttributeError: 'Coordinate' object has no attribute 'Stage'
I noticed some differences in capitalization in the file, the class stage was capitalized as was the stage for

Code: Select all

        stage1=Stage([
            "1111111111", ...
I tried removing the capitalization of both and keeping it lowercase (not sure if this was originally deliberate or a mistake).
Still getting an error:

Code: Select all

I'm sorry, but an [code]
uncaught exception occurred.

While running game code:
File "game/script.rpy", line 129, in script
if here.stage[here.y][here.x]=="a":
File "game/script.rpy", line 129, in <module>
if here.stage[here.y][here.x]=="a":
TypeError: 'stage' object does not support indexing
[/code]

Here is the full init section from the dungeon script.

Code: Select all

# This file is in the public domain.

init -1 python:
    
    class Stage(object): #I tried changing this to a lowercase s too.
        
        '''
        Class which contains map itself, auto mapping record, and encounter enemy.
        '''
        
        def __init__(self, map, enemy=None):
            self.map=map
            self.enemy=enemy
            self.mapped=[]
            for n,i in  enumerate(map):
                self.mapped.append([])
                for j in i:
                    self.mapped[n].append(0)
                    
    class Coordinate(object):
        
        '''
        Class used for calculating relative coordinate.   
        '''
        
        def __init__(self, stage=None, y=0, x=0, dy=0, dx=0):
            self.stage=stage
            self.y=y
            self.x=x
            self.dy=dy
            self.dx=dx 
            
    class Minimap(object):
        
        '''
        A minimap. Minimap(current_coordinate).sm is a displayable to show this minimap.
        '''
        
        def __init__(self,child):
            self.sm = SpriteManager(ignore_time=True)
            for n,i in enumerate(child.stage.map):
                for m, j in enumerate(i):
                    if child.stage.mapped[n][m]==1:
                        if j in ["1"]:
                            d = Solid("#666", xysize=(12,12))
                        else:
                            d = Solid("#fff9", xysize=(12,12))
                    else:
                        d = Solid("#0000", xysize=(12,12))
                    self.add(d,n,m)
            if child.dy==-1:
                self.add(Text("↑",size=12),child.y,child.x)
            elif child.dx==1:
                self.add(Text("→",size=12),child.y,child.x)
            elif child.dy==1:
                self.add(Text("↓",size=12),child.y,child.x)
            else:
                self.add(Text("←",size=12),child.y,child.x)
                    
        def add(self, d,n,m):
            s = self.sm.create(d)
            s.x = m*12+12
            s.y = n*12+12

User avatar
Natalie
Newbie
Posts: 17
Joined: Thu Jun 16, 2016 10:50 pm
Projects: Serment - Contract with a Devil
Contact:

Re: Adding events to a dungeon crawler.

#6 Post by Natalie » Sun Jul 16, 2017 9:11 pm

Change this

Code: Select all

here.stage[here.y][here.x]=="a"
to this

Code: Select all

here.stage.map[here.y][here.x]=="a"
Image
Follow Serment (JRPG dungeon crawler/Visual Novel hybrid) on Steam!

User avatar
Milkymalk
Miko-Class Veteran
Posts: 659
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Adding events to a dungeon crawler.

#7 Post by Milkymalk » Mon Jul 17, 2017 12:03 am

What Natalie wrote is correct. Sorry, there was no way to know for sure without seeing the code first. You should make a habit out of posting all relevant parts with your opening post, which includes the code for involved classes.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
ComputerArt.Club
Veteran
Posts: 409
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Adding events to a dungeon crawler.

#8 Post by ComputerArt.Club » Mon Jul 17, 2017 12:26 am

Thank you very much Natalie. I saw pictures of Serment while researching Renpy RPG/Dungeon crawler games, it looks very beautiful, though I haven't had a chance to play it yet. I have a feeling that code in your game is probably quite detailed.

Your change is stopping the error, but the jump does not occur. Hmm.
Another step closer to working, but no cigar. I tried typing jump exit in the console while in the dungeon area and it worked.
Hmm. It must be a really stupid mistake. Maybe the code is the the wrong section?

I tried putting it in the init section, game freezes on load,
tried in the python section, jump exit is invalid syntax (I guess because jump isn't python).
Is that why people add renpy.whatever to things?
So the code is back at the start of the game, before calling dungeon, not in a python section.
The game loads, dungeon plays, no event.

Code: Select all

    if here.stage.map[here.y][here.x]=="a":
        jump exit
I am still using lowercase code for the stage class.

Also, for anyone else interested, I found new code by the same creator with a complete overhaul on Github: https://github.com/nyaatrap/renpy-utili ... _crawl.rpy. Unfortunately, I tried adding it to my game and the game freezes before it starts, no errors raised (I also tried adding the adventurer.rpy, deleting the files and code, and "jump entrance" as I believe the the appropriate way of starting the dungeons with the new code. Im probably making another mistake though.

User avatar
Natalie
Newbie
Posts: 17
Joined: Thu Jun 16, 2016 10:50 pm
Projects: Serment - Contract with a Devil
Contact:

Re: Adding events to a dungeon crawler.

#9 Post by Natalie » Mon Jul 17, 2017 1:31 am

Are you putting this code outside of the "while" loop in the "dungeon" label?

Code: Select all

if here.stage.map[here.y][here.x]=="a":
    jump exit
Because it needs to be in there for it to work.

You should put it under this line in the Framework:

Code: Select all

# Check events. If it happens, call a label or jump out to a label.
If you want the event to trigger before checking for random battles, put it above the code checking for battle, like this:

Code: Select all

# Check events. If it happens, call a label or jump out to a label.

if here.stage.map[here.y][here.x]=="a":
    jump exit

if here.stage.enemy is not None and renpy.random.random()< .2:
    call battle(player=hero, enemy=here.stage.enemy)
Also, it would be really hard for someone who has never examined nyaatrap's dungeon crawl Framework code before to answer questions like this, since you don't know which are the relevant code sections to provide in your post yet. There's nothing wrong with that of course, everyone starts as a beginner. However, I would recommend taking a bit more time to try to completely understand the Framework line by line before modifying the base code any further. It might be really confusing and intimidating at first, but it would save you a lot of time in the future.
Image
Follow Serment (JRPG dungeon crawler/Visual Novel hybrid) on Steam!

User avatar
ComputerArt.Club
Veteran
Posts: 409
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Adding events to a dungeon crawler.

#10 Post by ComputerArt.Club » Mon Jul 17, 2017 10:00 am

Natalie wrote:Are you putting this code outside of the "while" loop in the "dungeon" label?

Code: Select all

if here.stage.map[here.y][here.x]=="a":
    jump exit
Because it needs to be in there for it to work.
Thank you Natalie, you were correct again! You solved my two biggest problems, I am very grateful. I had spent a great deal of time trying to figure them out, to no avail. I am very lucky that you responded to the post, as you said, it is difficult to solve unless you are familiar with the source material, especially given the fact I did not post all of the code.

I will try to continue to improve so that I can solve these problems myself.
Thanks also to Milkymalk! Both of you were very helpful and generous with your time.

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
Contact:

Re: [Solved] Adding events to a dungeon crawler.

#11 Post by hyperionthunder » Tue Jun 12, 2018 11:23 am

This place is a blessing. Found the answer I was looking for and applied it to my dungeon. Thanks for such a simple solution!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]