Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Fri May 24, 2013 1:04 pm

All times are UTC - 5 hours [ DST ]


Forum rules


Ask questions about one topic per thread, and use a descriptive subject. "NotImplemented error in script.rpy" is a good subject, "Tom's problems" is not. Remember to include all of traceback.txt or error.txt when reporting a problem, as well as the relevant lines of script. Use the [code] tag to format scripts.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Jun 17, 2012 8:04 pm 
Veteran

Joined: Sat Feb 26, 2011 9:36 am
Posts: 264
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Projects: Rzeczpospolita Polska 1647
I've been trying out this code, and it returns the error mentioned in the thread title.

Code:
init python:
    class Item:
        def _init_(self, name, cost, amount):
            self.name = name
            self.cost = cost
            self.amount = amount
           
    class Formulae:
        def _init_(self, name, item1, item2, item3, item4, result):
            self.name = name
            self.cost = cost
            self.item1 = item1
            self.item2 = item2
            self.item3 = item3
            self.item4 = item4
            self.result = result
           
    class Inventory:
        def _init_(self, treasury):
            self.treasury = treasury
            self.items = []
       
        def inventory_check (self, item):
            for item in self.items:
                if item.amount <= 0:
                    self.items.remove(item)
                    return False
                else:
                    return True
           
        def buy(self, item):
            if self.treasury >= item.cost:
                if item in self.items:
                    pass
                else:
                    self.items.append(item)
                item.amount += 1   
                self.treasury -= item.cost
                return True
            else:
                return False
       
        def craft (self, item):
            self.inventory_check(self)
            if Formulae.item1 in self.items:
                item1.amount -= 1
                self.inventory_check(self)
                if Formulae.item2 in self.items:
                    item2.amount -= 1
                    self.inventory_check(self)
                    if Formulae.item3 in self.items:
                        item3.amount -= 1
                        self.inventory_check(self)
                        if Formulae.item4 in self.items:
                            item4.amount -= 1
                            self.inventory_check(self)
                            self.items.append (Formulae.result)
                            return True
                        else:
                            item3.amount += 1
                            self.inventory_check(self)
                            return False
                    else:
                        item2.amount +=1
                        self.inventory_check(self)
                        return False
                else:
                    item1.amount +=1
                    self.inventory_check(self)
                    return False
            else:
                self.inventory_check(self)
                return False
                           
        def earn(self, earnings):
            self.treasury += earnings


label start:
    python:
        inventory = Inventory()
        iron = Item("Iron Ingot", cost = 50, amount = 0) # This is the line where the program returns an error
        iron_dagger = Item("Iron Dagger", cost = 100, amount = 0)
        iron_dagger_formula = Formulae ("Iron Dagger", iron, 0, 0, 0, Item.iron_dagger)


Could anyone tell me what has gone wrong? Also, is my code structure sound?

Thanks beforehand!

_________________
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.


Top
 Profile Send private message  
 
PostPosted: Sun Jun 17, 2012 10:30 pm 
Regular

Joined: Tue Apr 03, 2012 9:17 am
Posts: 88
Location: Seoul, South Korea
Projects: Dandelion
Organization: Cheritz
Your constructors need two underscores on each side, looks like you only have one.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: jack_norton


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group