Requesting following features

I haven't read the whole script, but I did notice that you used the file name test.py - I also tried this and it turns out that it won't work. :p Use some other file name and you might get better results.

An alternative to writing and reading from file would be to store the dictionary in a class. I do this all the time and this sort of thing can be found in the modules I've written for you also. (There is most of the time a some array defined right after the class definition, making the name a class variable.)

It would also be possible to store a dictionary as a field of an instance of a class. So each "store" would be a new instance of that class then, with its own inventory dictionary.

But for any sort of real use of your script you should of course be able to store and retrieve the data. But you don't need to learn how to do this just to be able to mod CivIV. Because, as God-Emperor pointed out - and as I've already solved this for you within you mod's Python content - the game has its own file I/O procedures. You only need to be able to tap into that.
 
ok I will try the different file name, but why would it give a different result?
 
I don't know, but since I'm assuming you're saving your file into the Python install folder there is probably already something called test present. I know that it doesn't make any sense, and I wasted good learning time on file I/O using the name test also. Why now call your file inventory.dat?
 
I looked at your script and thought I'd let you know that you can replace the new() function with "\n" which is the string type representation of a new line. So instead of this:
Code:
    print "These are your options:"
    new()
...you could just have this:
Code:
    print "These are your options:\n"
If you wanna put a nicer face on it you could define it as a constant:
Code:
newLine = "\n"
...
    print "These are your options:" + newLine

Other than that I think you got a nice little program going on there! :goodjob: I think its very good how you're inclined to define all these little functions along the way, instead of just creating one single massive script with repetitive code.

edit: You realize that you define the function program() in both sets of code, right? Because one will replace the other, which may be what you're experiencing? The import statement you're using is also a bit dangerous in this respect. You really shouldn't be using the asterisk option carelessly. Try this instead:
Code:
from Dictionaries import exception
Or simply:
Code:
import Dictionaries
def program():
    Dictionaries.exception()
 
Ok, so I was confused before. :rolleyes:

I now realize that you're writing a dictionary to a file and simply converting it to a string with str() isn't sufficient if you wanna be able to read it and convert back to dictionary type.

So what God-Emperor said mostly applies, but instead of using the game's setScriptData() and getScriptData() methods you use the built-in read() and write() functions.

To get you started you need the Pickle module. So you import it:
Code:
import Pickle
Then you use Pickle.dumps() to convert the dictionary into a pickled string type (one that can be unpickled later) and Pickle.loads() to unpickle it into its original (dictionary) state.

The alternative would be to take each key and value in the dictionary and store those on individual lines in string type on the file. Then you'd have to rebuild the dictionary from these strings, convert the non-string values into some other type (integer, probably) and rebuild the dictionary key-value pair at a time. This would actually be a good learning exercise. :D
 
ok I will try pickle soon! Yeah I am very much inclined to write up functions as to not have to repete them...
 
I just tested all the new features and they all work... now to test just the rest of the rebellions (haven't seen slaves cultural or civil war yet!)
 
You can actually trigger the slave revolts with some Python code. Or, you could if you had access to the Python console. ;) Joking aside, you can just slap any code at the end of practically any .py file and have it be fired at any point in the game. Its just like using the console, really. Just delete the code once the effect has taken effect. :D
Code:
gc.getPlayer(0).trigger(23)
This should cause a Roman city to experience a slave revolt.
 
ok I will do that when I get frustrated from not having it :D

me and my friend just finsihed translating everything which is a big relif :D

after my testing I think I will need to do my playthrough while waiting for your code!
 
how is it going?
I still havent got around to testing yet but I have finsihed EVERYTHING else :D
 
I'll get back to you with the sample class this weekend. Good luck with the testing!
 
I wanted to supply you with an example of the senate mission class - before you start adding code to that module. Because it would help to get you started in the right direction. This was some time ago however and the discussion on the subject is pretty well buried in the archive. But I'll try to write something up for you nonetheless.
 
do you think the catapult code will ever get fixed or should I just remove it? The c++ error could be because I am not usingthe latest version of the dll only up to where ethnic buildings were added... Would that be it?
 
found these in the debug log...

Barbarian valid catapult constructors:

Gallic Rebel valid catapult constructors: (4, 14) (4, 14) (4, 14) (1083864368, 1097703136) (4, 14) (4, 14) (4, 14) (4, 14) (4, 14) (4, 14) (-2147483647, -2147483647) (9, 18) (9, 18)

you think this could be causing the problems? Barbs and randomly high coords?

also when will the class be done :D
 
I wouldn't give up on the catapult construction code - it was quite the job to complete, actually. :p I'll just have to take a closer look myself, and the debug lines are very interesting indeed... (The invalid coordinates could be from units that are no longer valid themselves - dead units basically. So they should definitely not be spawning any catapults...) Again - do you have a save game of that particular occurrence?

All I've done on the senate mission class is review some of the discussion from earlier - I saved all the posts for when I get the the time to get into it. Right now I really have my hands full with other stuff, but I'll get there...
 
The issue seems to be that the catapult construction code somehow gets invalid (dead) units which in turn are placed on invalid "plots". Try adding this line:
Code:
        def checkUnits(self):
                for pUnit, pPlot in list((pUnit, pUnit.plot()) for pUnit in self.iterateUnits()):
                        [B]if pPlot.isNone() or pUnit.isDead(): continue[/B]
                        if pPlot.getFeatureType() == eForest:
                                if isEnemyTerritory(pUnit, pPlot, self.pCivPlayer.get(CyTeam)) or self.isUsed(pUnit): return
                                self.activateOverwatch(pUnit, pPlot)
                                break
 
ok I will try that later! Pretty lucky I went to see what rebellion carthage got and saw those catapultcontructors lol
 
I made a cople of new functions to do with pickle that was mentioned earlier that are...
Code:
#PickleJar functions

def OpenPickleJar(name):
    pjo = open(name, "r")
    read = pjo.read()
    PJO = pickle.loads(read)
    return PJO
def PickleJar(variable, name):
    pj = open(name ,"w")
    pj.write(pickle.dumps(variable))
    pj.close

and of course in the code it looks like this :D

Code:
        elif option == 3:
            submenu("Address Book", "Address")
            while loop2 == 1:
                address = OpenPickleJar("PickleJarAddress.txt")
                choice = selection()
                if choice == 1:
                    show(address)
                elif choice == 2:
                    add(input("Enter person's name(add within ''): "), input("Enter Address: "), address)
                    PickleJar(address, "PickleJarAddress.txt")
                elif choice == 3:
                    delete(input("Who's address would you like to delete?(add within '', case sensitive!): "), address)
                    PickleJar(address, "PickleJarAddress.txt")
                elif choice == 4:
                    change(input("Enter person's name?(add within ''): "), input("New Address: "), address)
                    PickleJar(address, "PickleJarAddress.txt")
                elif choice == 5:
                    print "Returning to main menu!"
                    menu()
                    PickleJar(address, "PickleJarAddress.txt")
                    loop2 = 0
                else:
                    error()

pretty proud of my self :D
 
Very nice! :goodjob:

But you might still wanna know how to store data in memory, like a dictionary of addresses. You could add a Storage class to your application and make the dictionary a class variable (not an attribute of an instance of that class).

And then you add a save method and a load method to that class, which in turn pickles/unpickles the dictionary when prompted to. Like when the program is started/exited. The trick is of course to be able to load a non-existing pickled dictionary the first time you start the program. :p This can be achieved with a try-except clause - the exception would then set the dictionary to a default empty array.

The coming week, including this weekend, is a bit crazy for me, so don't expect anything from me. I don't wanna keep you hanging so you should just go ahead with the senate missions once you've done with testing/debugging.

I guess my main point for my intended sample senate mission class was whether or not you wanna have one class for all the types of missions/rewards, or if those could in fact be sub-classes. Because then you wouldn't add methods to the main class for each variety, but rather have a default method for all the functionality of the mission/reward - inside each individual sub-class.

I'm sorry if this doesn't make much sense here - I really should read up on the previous discussion and make the code. Too bad I'm pressed for time at the moment. :p
 
Back
Top Bottom