PyTFall > PyTFall: Bugs and Game balancing

Code review

(1/8) > >>

rudistoned:
Hey guys, I thought we could start a thread to discuss changes to the code (if we think they need discussing).

I noticed that the current revision of master (6cc3e2d77e1e38cd327d244b6c2f19c7d138a770) throws the following error when trying to load image files on windows:


--- Quote ---I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/library/screens/pyt - screens - nextday.rpy", line 6, in script
  File "game/library/screens/pyt - screens - nextday.rpy", line 130, in python
  File "game/library/classes - characters.rpy", line 668, in python
  File "game/library/functions.rpy", line 148, in python
Exception: Backslash in filename, use '/' instead: u'D:\\PyTFall\\renpy-6.15.4-sdk\\pytfall/game\\content/chars/naruto/Sakura/strip (1).png'

--- End quote ---

Revision a9e216809559bd2a7f98906cef19762116e0e7b7 (the one the "tags" branch is based on) does not have this problem, so it was probably introduced since.

If one of you feels like fixing it, the following function might come in handy. However, once we use the TagDatabase to get paths to image files, the image loading code will be changed anyway, so you could just ignore it for now.

--- Code: ---    def normalize_path(path, start=""):
        '''Returns a filesystem path following the conventions of the local OS.
       
        If start is empty, an absolute path will be returned.
        If start is not empty, a path relative to start will be returned.
        '''
        path = os.path.normpath(path)
        # determine an absolute version of path
        if os.path.isabs(path):
            abspath = path
        else:
            abspath = os.path.normpath(os.path.join(gamedir, path))
        # return the normalized path
        if start=="":
            normpath = abspath
        else:
            startpath = os.path.normpath(start)
            normpath = os.path.relpath(abspath, start=startpath)
        return normpath

--- End code ---

Xela:

--- Quote from: rudistoned on June 15, 2013, 11:50:04 AM ---Hey guys, I thought we could start a thread to discuss changes to the code (if we think they need discussing).

I noticed that the current revision of master (6cc3e2d77e1e38cd327d244b6c2f19c7d138a770) throws the following error when trying to load image files on windows:

Revision a9e216809559bd2a7f98906cef19762116e0e7b7 (the one the "tags" branch is based on) does not have this problem, so it was probably introduced since.

If one of you feels like fixing it, the following function might come in handy. However, once we use the TagDatabase to get paths to image files, the image loading code will be changed anyway, so you could just ignore it for now.

--- Code: ---    def normalize_path(path, start=""):
        '''Returns a filesystem path following the conventions of the local OS.
       
        If start is empty, an absolute path will be returned.
        If start is not empty, a path relative to start will be returned.
        '''
        path = os.path.normpath(path)
        # determine an absolute version of path
        if os.path.isabs(path):
            abspath = path
        else:
            abspath = os.path.normpath(os.path.join(gamedir, path))
        # return the normalized path
        if start=="":
            normpath = abspath
        else:
            startpath = os.path.normpath(start)
            normpath = os.path.relpath(abspath, start=startpath)
        return normpath

--- End code ---

--- End quote ---

I've just pushed and a fix for the windows path should be there as well.

rudistoned:

--- Code: ---max_page = len(content) / page_size if len(content) % page_size not in [0, page_size] else (len(content) - 1) / page_size

--- End code ---

I've never seen this syntax before. Am I correct in assuming that "len(content) / page_size" is assigned to "max_page" if "len(content) % page_size not in [0, page_size]" and if not "(len(content) - 1) / page_size"  is assigned to "max_page"? If so, why not write it like this:

--- Code: ---if len(content) % page_size not in [0, page_size]:
    max_page = len(content) / page_size
else:
    max_page = len(content) - 1) / page_size

--- End code ---

Xela:

--- Quote from: rudistoned on June 20, 2013, 04:39:24 PM ---
--- Code: ---max_page = len(content) / page_size if len(content) % page_size not in [0, page_size] else (len(content) - 1) / page_size

--- End code ---

I've never seen this syntax before. Am I correct in assuming that "len(content) / page_size" is assigned to "max_page" if "len(content) % page_size not in [0, page_size]" and if not "(len(content) - 1) / page_size"  is assigned to "max_page"? If so, why not write it like this:

--- Code: ---if len(content) % page_size not in [0, page_size]:
    max_page = len(content) / page_size
else:
    max_page = len(content) - 1) / page_size

--- End code ---

--- End quote ---

Feel free to swap, either way works :)

Xela:
@ Rudi/Matt

Take a look at this function:


--- Code: ---    # Throwing dice. value = chance, max - limits
    # if dice(60): means probability of 60%
    def dice(value, max=100, show=True):
        number = random.randrange(0,max+1)
        if number <= value:
            result = True
        else:
            result = False
        if config.developer and show:
            notify(u"Resulted in %d from %d, limit - %d, and result - %s." % (number,max,value,str(result)))
        return result
--- End code ---

This is from Alkion (written by Roman, not me) but this seems flawed because it actually picks from 101 numbers and not 100. Can any of you confirm this, I ran this on pure python 2.7 and it seems to agree with me.

Code should be:


--- Code: ---    # Throwing dice. value = chance, max - limits
    # if dice(60): means probability of 60%
    def dice(value, max=100, show=True):
        number = random.randrange(1, max+1)
        if number <= value:
            result = True
        else:
            result = False
        if config.developer and show:
            notify(u"Resulted in %d from %d, limit - %d, and result - %s." % (number,max,value,str(result)))
        return result
--- End code ---

Otherwise dice(1) actually means 2% chance because number variable can be anything in range of 0 to 100 (BUT INCLUDING 0 as well)  and same counts for any other throw? What do you think?

Navigation

[0] Message Index

[#] Next page

Go to full version