|
Squack McQuack posted:1. Since I'm new to programming, I never considered the game running its update functions at different rates on different computers. One of my classes contains the main game's sprites. The update function for this class applies gravity when the sprite is jumping. On my computer, this was applied 60 times per second. I tested on another computer though, and it seems to be applied at a much faster rate, which results in the sprite barely jumping off the ground. Not sure about Cocos2D, but in pyglet, the callback should take only one argument, dt, which is the amount of time that is passed since the callback was previously called. Use a formula for gravity that explicitly uses time. Unless Cocos2D offers something else, you should be doing something like: Python code:
|
# ? Jul 7, 2014 15:39 |
|
|
# ? May 9, 2024 11:22 |
|
SurgicalOntologist posted:Not sure about Cocos2D, but in pyglet, the callback should take only one argument, dt, which is the amount of time that is passed since the callback was previously called. Use a formula for gravity that explicitly uses time. OK, that's starting to make sense. Right now the "game sprites" class has an update function that includes a lot of stuff, including gravity: code:
SurgicalOntologist posted:Use a formula for gravity that explicitly uses time.
|
# ? Jul 7, 2014 19:48 |
|
Squack McQuack posted:I'm unclear on the difference between "self.schedule()" and "pyglet.clock.schedule()". It appears it works the same way, I just wasn't familiar with Cocos2D. You can pretty much ignore my code example. Squack McQuack posted:Also, I still don't quite get how this will help if different computers are calling update at different rates. Does the solution have to do with what you said here? Yes. The parameter dt is the amount of time that's passed since the last update call. If you want the sprite's behavior to depend on clock time, not frequency of calling updates, then you need to use this parameter in some way. In your code you are not using dt. Think about the units that your GRAVITY variable has. Pixels per second squared I would guess. In other words change in velocity (pixels per second) per second. At least that's what it should be. But you decrement fall_rate by 200 every time update is called. So your GRAVITY variable actually has units of pixels per second per update call. What you want is this: Python code:
|
# ? Jul 7, 2014 20:08 |
|
SurgicalOntologist posted:So if update is being called once per second, or ten times per second, fall_rate will change at the same rate. Indeed you want to multiply by dt every time you are applying a rate in a callback. (Not sure if velocity is built-in to Cocos2D or if you are using it to change position in another callback. If the latter you will also need to multiply by dt there) Great, I think I get it. I'll give it a try later tonight and report back. Thanks! Edit: That did it! Thanks a lot, it would have taken me so long to solve that on my own. I'm still having a problem with #2 unfortunately. So far I've gotten it to work on 2 computers (Win7 and Win8) and failed on one (Win7). Maybe it has to do with the capability of the hardware? The failed computer is fairly old, from 2008 or so. quote:2. I want to convert this game to an exe file so others can play it. I did this using PyInstaller, and got the exe file to run successfully on my own computer. I ran into trouble on another computer, though. The game runs but there's a weird graphical glitch - there's one sprite that is displayed as a white block. Squack McQuack fucked around with this message at 02:19 on Jul 8, 2014 |
# ? Jul 7, 2014 20:45 |
|
Is there a way to open and close URL sessions multiple times in the same program? I have a URL that returns a JSON depending on the ID number given. I need to go through about 4000 of these. Right now the server times out after ~100 iterations of a for loop. What can I do to do bursts of data collection and spit it all out to one file?
|
# ? Jul 8, 2014 16:44 |
|
raej posted:Is there a way to open and close URL sessions multiple times in the same program? Python code:
I'm not sure I understood your question, so this might not be what you're looking for.
|
# ? Jul 8, 2014 16:57 |
|
Yea use requests. I dunno what you're doing exactly, but something like this should work:Python code:
Dominoes fucked around with this message at 17:28 on Jul 8, 2014 |
# ? Jul 8, 2014 17:14 |
|
http://www.ratebeer.com/json/bi.asp?k=tTmwRTWT-W7tpBhtL&b=[ID] This url spits out the JSON for that brewery. I was originally doing a for loop that went from [ID] 1 to 1000, but like I said, that was timing out. I was also doing it in PHP which was probably a stupid idea.
|
# ? Jul 8, 2014 17:24 |
|
GET requests can time out, but they shouldn’t time out because you took a long time between two of them. This is working: Python code:
|
# ? Jul 8, 2014 17:41 |
|
HardDisk posted:GET requests can time out, but they shouldn’t time out because you took a long time between two of them. Thanks! I tried this out, and since it's starting with 0 (which times out) I receive an error. How would I set a start and end number to iterate through? Adding in "i=16000" before the for loop still spits out 0 when it runs.
|
# ? Jul 8, 2014 21:00 |
|
raej posted:Thanks! I tried this out, and since it's starting with 0 (which times out) I receive an error. How would I set a start and end number to iterate through? Adding in "i=16000" before the for loop still spits out 0 when it runs. Python code:
* Anyone know why? Dominoes fucked around with this message at 21:50 on Jul 8, 2014 |
# ? Jul 8, 2014 21:34 |
|
Dominoes posted:
I think so you can do len(whatever) instead of len(whatever) - 1.
|
# ? Jul 8, 2014 21:57 |
|
Dominoes posted:First argument for range() is the start index, second is one after* the end. Optional third lets you set an interval other than , ie skip that many indexes each iteration. It's the same way slices work, and it's tied into the choice of zero-based indexing. The other choice, besides zero- or one-based indexing, is whether the interval is closed or open, and Python uses half-open intervals (open on the left, closed on the right), which is what we see with range. Part of the reason for choosing zero-based indexing is because one-based doesn't really work with half-open intervals, and half-open intervals are elegant. https://plus.google.com/115212051037621986145/posts/YTUxbXYZyfi Why are half-open intervals elegant? Well, for one, len(range(start, end)) = end - start. For another, if you want to have two ranges that connect, you can do first, second = range(end//2), range(end//2, end) (if end is even, in this example). In other words you pick up where you previously left off without doing a +1. With any indexing choice you will have to do +1 or -1 in some cases, in Python where that comes up is with range if you know the last number you want, you have to do +1. But with something like Matlab with open intervals and one-based indexing, you have to do +/- 1 all the loving time and people always get it wrong and make off-by-one errors. By the way, does anyone have a Chrome plugin or AutoHotKey script or anything that makes a shortcut to insert [fixed][/fixed] around a selection? I am sick and tired of typing that.
|
# ? Jul 8, 2014 21:57 |
|
SurgicalOntologist posted:By the way, does anyone have a Chrome plugin or AutoHotKey script or anything that makes a shortcut to insert [fixed][/fixed] around a selection? I am sick and tired of typing that.
|
# ? Jul 9, 2014 01:42 |
|
Master_Odin posted:In the Quick Reply box in SALR, if you hit Ctrl+F when you've selected text, it'll warp it in the fixed tags. Good to know, thanks. I disabled the Quick Reply box before I started posting code often, for some long-forgotten reason. This is a good reason to re-enable it.
|
# ? Jul 9, 2014 03:47 |
|
Dominoes posted:
Because range(N) spits out a list that doesn't include N, so it wouldn't make sense for the list produced by range(A, B) to include B, either. They probably would include the provided value if Python counted from 1 instead of 0 (but that would be terrible for other reasons)
|
# ? Jul 9, 2014 09:05 |
|
Thanks for the explanations.SurgicalOntologist posted:With any indexing choice you will have to do +1 or -1 in some cases, in Python where that comes up is with range if you know the last number you want, you have to do +1. But with something like Matlab with open intervals and one-based indexing, you have to do +/- 1 all the loving time and people always get it wrong and make off-by-one errors.
|
# ? Jul 9, 2014 17:27 |
|
Why is this code not working? I've been looking at it for ages now with glazed eyes aha. In python 3.4 if that info is needed.code:
code:
|
# ? Jul 9, 2014 23:15 |
|
When you do:code:
Passing in a value to be filled with data as an argument like that seems like a habit from C/C++; perhaps try having the 'rand_dict' function return the data instead?
|
# ? Jul 9, 2014 23:35 |
|
Carrier posted:Why is this code not working? I've been looking at it for ages now with glazed eyes aha. In python 3.4 if that info is needed. I think what the above post says is correct. But even then I would wonder why you need rand_dict() to take any arguments at all, since you're sending it an empty dictionary every time anyway. Something like this maybe: code:
|
# ? Jul 9, 2014 23:50 |
|
Ahh thank you! I've just come off of a couple of days full of C so I think you are right in where that particular habit came from!
|
# ? Jul 10, 2014 07:45 |
|
I'm having to go through and clean some data that I grabbed. A lot of them have unicode characters that pop errors, for example:Python code:
Python code:
|
# ? Jul 10, 2014 21:08 |
|
I had a similar problem and used the unidecode library, which for example will replace an accented character with the closest ascii character. If you just want to delete the unicode characters it's probably easier. For example if you import string you will find string.digits, you can remove all characters that aren't in that.
|
# ? Jul 10, 2014 21:30 |
|
Or use this one-liner to remove all non-ascii characters:Python code:
|
# ? Jul 10, 2014 21:37 |
|
Shouldn't it be less than or equal to 128? or is it 0 - 127?
|
# ? Jul 10, 2014 22:42 |
|
Yup, 0 - 127. You can even see it in the exception you posted:Python code:
|
# ? Jul 10, 2014 22:45 |
|
the posted:
Where and why are you trying to encode internationalized text as ASCII? Are you absolutely sure that you need to do this?
|
# ? Jul 10, 2014 22:58 |
|
I have a .py file named transpose_plans.py located in "C:\\JCuervo\\work\\analysis" and I want the text files output to be located in "C:\\JCuervo\\work\\repast\\cplans\\york\\output\\". Is this the best way to get the relative(?) path from transpose_plans.py to the output folder: Python code:
|
# ? Jul 11, 2014 01:39 |
|
Jose Cuervo posted:I have a .py file named transpose_plans.py located in "C:\\JCuervo\\work\\analysis" and I want the text files output to be located in "C:\\JCuervo\\work\\repast\\cplans\\york\\output\\". Did you try it? I think you'll find that os.path.dirname('transpose_plans.py') will return an empty string. It returns the directory component of a path, the path 'transpose_plans.py' has no directory component. What's the best way depends on a lot of things. Will this ever get run on a different filesystem? Different absolute paths? Different OSes? If not, just hardcode the output folder and be done with it, maybve set it at the top of the script as a constant so you can easily find it again if you want to change it in a year. If the answer to those questions is a yes, then you can start thinking of the "best" way. I suppose you would have to decide if you want the output directory to be defined invariantly in relation to the script itself, or to some input directory/file.
|
# ? Jul 11, 2014 02:13 |
|
Lysidas posted:Where and why are you trying to encode internationalized text as ASCII? Are you absolutely sure that you need to do this? All I know is I'm grabbing zip codes via SQL request from US/Canada and trying to store them in a list in Python. I have no earthly idea where the weird codes are coming from. For some reason some of the zipcodes will come out like code:
|
# ? Jul 11, 2014 02:41 |
|
the posted:I'm having to go through and clean some data that I grabbed. A lot of them have unicode characters that pop errors, for example: SurgicalOntologist posted:I had a similar problem and used the unidecode library, which for example will replace an accented character with the closest ascii character Moddington posted:Or use this one-liner to remove all non-ascii characters: if you're desperate to get a string out of a sequence of mostly ascii, you can use '\xa034241\x80'.decode('ascii', 'ignore') in py2. u'34241' Lysidas posted:Where and why are you trying to encode internationalized text as ASCII? Are you absolutely sure that you need to do this? This is the more important question — how are you getting your data? you might find that you will need to set an encoding somewhere, which will actually fix your problem
|
# ? Jul 11, 2014 03:19 |
|
tef posted:This is the more important question — how are you getting your data? you might find that you will need to set an encoding somewhere, which will actually fix your problem I'm using Beatbox to query a database in Salesforce. I'm grabbing a list of Account zip code fields. They get returned as type 'instance' and I convert them to a string before doing anything with them. Which leads to my next question: I need to be able to check to see if the entries are blank. Some of them didn't have zip codes, so nothing was written in the zip code portion of the column: code:
How can I do that? edit: Ended up doing this: code:
the fucked around with this message at 03:44 on Jul 11, 2014 |
# ? Jul 11, 2014 03:39 |
|
The first step of whatever you're doing should be to turn those records into dictionaries so you could refer to the fields by name like God intended. Either you did something wrong along the way or that is a terrible API. I'm pretty sure it's the latter. Point is, patch the leak first by turning those lists into dictionaries. Handle the missing data during that process.
|
# ? Jul 11, 2014 06:44 |
|
Hi, I am new to python (and programming in general) but so far I am a huge fan of python. Right now I am tinkering with tkinter, and I ran into a problem. code:
My goal is to have a function generiereButtons that I can pass an array of classes and it builts the radio buttons for each element. If I run the code inside the generiereButtons function without the function itself, it works fine, but if I put it in a function it no longer works, because Zahl.sel() tries to access label which does not exist outside the scope of generiereButton, if I understood that correctly. If I try to pass "label" with sel(label) I get an error because label is defined after the radio buttons. If I define label as a global var I probably cannot reuse the generiereButton function in several places without running into trouble at some point. How do I organise my code and functions to make this work? I haven't had any formal IT education so it's still difficult for me to come up with a proper hierarchical structure.
|
# ? Jul 11, 2014 09:13 |
|
BabyFur Denny posted:Hi, Make an "App" object (or a "GUI" or "Program" or whatever). Any information that you want shared between methods becomes an attribute of the App. So in your case, something like this: code:
|
# ? Jul 11, 2014 10:06 |
|
Ok, thanks for that, and I think I made some progress in understanding the whole thing. But the way you set up show_selection, I cannot do anything with the selected class, since the function only has access to zahl_var and it's value, not the actual class. If I try to pass the class to show_selection via command=self.show_selection(element) in the radio button (and of course using def show_selection(self, element): it no longer works. And I haven't found out how to switch the messagebox for a label that can be updated in show_selection. Here's the non-working code code:
|
# ? Jul 11, 2014 11:24 |
|
SurgicalOntologist posted:The first step of whatever you're doing should be to turn those records into dictionaries so you could refer to the fields by name like God intended. Either you did something wrong along the way or that is a terrible API. I'm pretty sure it's the latter. Point is, patch the leak first by turning those lists into dictionaries. Handle the missing data during that process. I have a problem of "I never work with dictionaries so I have no idea how to implement them so I never work with dictionaries." How would it help in this case?
|
# ? Jul 11, 2014 16:20 |
|
Dictionaries are one of the best things about Python .
|
# ? Jul 11, 2014 16:27 |
|
Yeah I keep hearing that, I guess I never use them enough to really understand their worth. So, as I understand it, it's a list that uses a key for output, right? That seems useful in a situation when I have multiple items associated with one unique entry (I know SurgicalOntologist has probably brought this up before when I've talked about the same work I'm doing).
|
# ? Jul 11, 2014 16:31 |
|
|
# ? May 9, 2024 11:22 |
|
the posted:I have a problem of "I never work with dictionaries so I have no idea how to implement them so I never work with dictionaries." You could do something like record['zip'] or record['name'] (or e.g. record.get('zip') if some records don't have zips) instead of always remembering that e.g. record[1] is the zip code, etc. Edit: or records[id_to_find]['zip'] if you have a dictionary of records, which are themselves dictionaries. the posted:Yeah I keep hearing that, I guess I never use them enough to really understand their worth. Dictionaries are mappings from keys to values. The only connection to a list is that both lists and dicts can store multiple things. Don't think of them list lists, think of them like look-up tables. If you have multiple items associated with the same key, then you could map keys to lists. If those multiple items are themselves well-represented by a dict, you could map keys to smaller dictionaries. Think about how you would find specific record if everything was lists? Python code:
Python code:
SurgicalOntologist fucked around with this message at 16:41 on Jul 11, 2014 |
# ? Jul 11, 2014 16:34 |