The Big Programming Thread - Page 443
| Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
|
Najda
United States3765 Posts
| ||
|
Shield
Bulgaria4824 Posts
| ||
|
Manit0u
Poland17493 Posts
On February 15 2014 07:57 darkness wrote: One thing that has driven me nuts recently is JVM. For example, when I don't look at my program's window, memory according to task manager could be 60k, but when I open the program's window and then open another window (e.g. Firefox), memory starts growing, e.g. until 61k, 62k or 64k. After a few seconds, it goes back to 60k again. Is this how JVM works or have I messed up something? I really don't understand what is going on here. I sometimes wish Java had some ARC model like Objective-C, so I can at least know that JVM is not doing shit. Wouldn't that be a spike in memory consumption when launching another program? | ||
|
Shield
Bulgaria4824 Posts
On February 15 2014 08:00 Manit0u wrote: Wouldn't that be a spike in memory consumption when launching another program? No, what I'm saying is that I monitor my program's memory usage. When I open my program's window quickly, then open some other window (e.g. Firefox), my program's memory keeps growing for a bit even though I don't look at that window or click anything, then that memory is more or less deallocated to go back to normal (I don't know if it goes back precisely to match bytes, but it's still e.g. 60k memory). It takes a few seconds for this to happen. I'm asking if that's standard from JVM's side to manipulate memory even if you do nothing but click on a program's window. Maybe JVM executes some event-driven code and allocates/deallocates memory? | ||
|
WarSame
Canada1950 Posts
| ||
|
Shield
Bulgaria4824 Posts
On February 15 2014 08:18 WarSame wrote: Hello everyone, reading week is this week! My classes are starting to require use of Objective C, so getting more practice with that is one of my goals for this week. Currently, the stage I am at is - I know what pointers are, how they function, and the basics of how to use them. In general, I don't use them on my own. So, if any of you have ideas for C projects that would require me to learn up/shore up on that front to do them, I would appreciate if you could share them. Thank you. So you need practice with pointers? One thing that may use pointers is some function to sort an array. I don't know why you stick with lower level stuff if you want to learn Objective-C though. ![]() | ||
|
WarSame
Canada1950 Posts
| ||
|
bangsholt
Denmark138 Posts
You want training with pointers - well, go make a C program that allocates memory to save N numbers and writes out the average - there you will need some pointers - then you can add on to it so you can choose different ways of sorting the numbers. | ||
|
WarSame
Canada1950 Posts
I'll give that a shot, thank you. | ||
|
Cyx.
Canada806 Posts
On February 15 2014 09:22 bangsholt wrote: What term? You use C. You want training with pointers - well, go make a C program that allocates memory to save N numbers and writes out the average - there you will need some pointers - then you can add on to it so you can choose different ways of sorting the numbers. One thing that really made me understand what was going on with my pointers was coding a doubly linked list that I then used in one of my projects extensively enough that I knew for DAMN sure there were no bugs in that code any more (well... I'm never sure. But I abused that thing lol). They're pretty tricky to debug, and looooots of pointers =D | ||
|
Shield
Bulgaria4824 Posts
On February 15 2014 09:28 WarSame wrote: I was using the term C earlier, but it was causing some confusion when I was asking questions. I guess I'll just stick with it, then. I'll give that a shot, thank you. C - a plain, procedural language C++ - superset of C, it supports C *and* offers more stuff (not only object-oriented programming) Objective-C - Apple's language, it supports C *and* offers object-oriented programming A bit informal, but you should distinguish all three. You can program C stuff in both C++ and Objective-C, but it's considered low level in general. ![]() Edit: The C Programming Language book | ||
|
misirlou
Portugal3241 Posts
On February 15 2014 09:29 Cyx. wrote: One thing that really made me understand what was going on with my pointers was coding a doubly linked list that I then used in one of my projects extensively enough that I knew for DAMN sure there were no bugs in that code any more (well... I'm never sure. But I abused that thing lol). They're pretty tricky to debug, and looooots of pointers =D This is what got me started on pointers aswell, back when I was learning C. Linked lists (you can start with one way lists and then move to double), learn the operations on them (add, search, remove, sorting), and then maybe look into trees if you want. + Show Spoiler + Pointers are really useful for making any data structure that isn't an array, even though you can use arrays to make stuff like binary trees. . More practice tips, when you're doing the functions that are supposed to do something, make them return a pointer, that way the functions will have much more uses and make you look at those beautiful "void* search(int value)" lines | ||
|
Crazyeyes
Canada1342 Posts
![]() | ||
|
ThatGuy
Canada695 Posts
. | ||
|
Crazyeyes
Canada1342 Posts
Here's the Stack Overflow thread: http://stackoverflow.com/questions/21792708/corona-lua-unable-to-access-table-value-after-collision And I'll copy the text over here in a spoiler for those of you who don't feel like leaving TL ![]() + Show Spoiler + I'm trying to get some collision detection working but I can't seem to figure out what the problem is. The error I'm getting is ...\main.lua:178:attempt to concatenate field 'name' (a nil value) What I have is this: I have a box (the "ship") that stays at a fixed X coordinate, but moves up and down. It's meant to go through a "tunnel" made up of two rectangles with a gap between them, and I'm trying to detect a collision between the ship and the walls of the tunnel (ie the rectangles). I get this error when the collision happens. A lot of my code is just modified versions of the official Corona documentation and I'm just not able to figure out what the problem is. Here are the relevant pieces of code:
I only get the error message once the two objects should collide, so it seems like the collision is happening, and it is being detected. But for some reason self.name and event.other.name are nil. It's my first time using LUA so I'm probably doing some things wrong, and it is a bit sloppy but as a learning exercise I'm not too concerned about that. Although the main issue here is of course solving the problem, any small criticisms or tips are always welcome. | ||
|
Oktyabr
Singapore2234 Posts
| ||
|
Nesserev
Belgium2760 Posts
| ||
|
Crazyeyes
Canada1342 Posts
On February 15 2014 14:17 Nesserev wrote: Well, I have no personal experience with LUA, but luckily it's a straightforward and easy-to-read scripting lanugage, and well, this is a problem that can occur in every language. (It also looks a bit like python) Check these things: - To what class does the function 'function onCollision(self,event)' belong to; and is self.name initialized in its constructor? (Check if you initialized a local variable called name instead of self.name) - Does the object that collides even have a member called self.name? Check what the types are of the objects that collide. Also, a nice way to debug, is to output information in every function. There are no classes. All of my code is in main.lua, which includes onCollision. I got the collision code from here, which also explains how it works in pretty simple terms. self should either be the ship or one of the walls (top/bottom), which have the .name property added right after creation. Physics are only enabled on the ship and the walls, so those are the only things that can collide. Furthermore, the physics engine can only have collisions between "dynamic" objects + other objects (so dynamic + dynamic or dynamic + static). Since the ship is my only dynamic physics body, and since I'm pretty confident that there is a collision taking place, we know that the ship is at least one of the bodies colliding and that the ship definitely has its .name property set. ... ... So while writing this post, or more specifically that last line, I thought "...wait, does it?" Motherfucker. I've spent like SIX HOURS trying to debug this shit AND I FUCKING FORGOT TO SET THE .name PROPERTY? Fuuuuuuck that. Thank you so much for responding. I had honestly given up at this point and was relying on someone fixing it for me. Jesus Christ I still can't believe what a stupid mistake that was. It works. After creating the ship, I give it a name now and that fixes it. Goddammit. | ||
|
phar
United States1080 Posts
On February 15 2014 08:07 darkness wrote: No, what I'm saying is that I monitor my program's memory usage. When I open my program's window quickly, then open some other window (e.g. Firefox), my program's memory keeps growing for a bit even though I don't look at that window or click anything, then that memory is more or less deallocated to go back to normal (I don't know if it goes back precisely to match bytes, but it's still e.g. 60k memory). It takes a few seconds for this to happen. I'm asking if that's standard from JVM's side to manipulate memory even if you do nothing but click on a program's window. Maybe JVM executes some event-driven code and allocates/deallocates memory? It's 4k memory. Are you having any performance issues because of this? Java has a gc, yes, so it's going to be fundamentally different than something like arc. But seriously dude, 4k memory. On February 15 2014 14:32 Crazyeyes wrote: Thank you so much for responding. I had honestly given up at this point and was relying on someone fixing it for me. Jesus Christ I still can't believe what a stupid mistake that was. It works. After creating the ship, I give it a name now and that fixes it. Goddammit. Some amount of this is just par for the course while writing software. You can mitigate some of it by starting smaller, writing unit tests, etc. But you'll never completely get away from dumb-as-shit bugs, just lessen the frequency and change the type. You can be glad that you have more tools to debug than LEDs and a oscilloscope at least, so it could be worse :p | ||
|
nunez
Norway4003 Posts
On February 15 2014 14:32 Crazyeyes wrote: There are no classes. All of my code is in main.lua, which includes onCollision. I got the collision code from here, which also explains how it works in pretty simple terms. self should either be the ship or one of the walls (top/bottom), which have the .name property added right after creation. Physics are only enabled on the ship and the walls, so those are the only things that can collide. Furthermore, the physics engine can only have collisions between "dynamic" objects + other objects (so dynamic + dynamic or dynamic + static). Since the ship is my only dynamic physics body, and since I'm pretty confident that there is a collision taking place, we know that the ship is at least one of the bodies colliding and that the ship definitely has its .name property set. ... ... So while writing this post, or more specifically that last line, I thought "...wait, does it?" Motherfucker. I've spent like SIX HOURS trying to debug this shit AND I FUCKING FORGOT TO SET THE .name PROPERTY? Fuuuuuuck that. Thank you so much for responding. I had honestly given up at this point and was relying on someone fixing it for me. Jesus Christ I still can't believe what a stupid mistake that was. It works. After creating the ship, I give it a name now and that fixes it. Goddammit. hahaha, the bittersweet release. | ||
| ||

. More practice tips, when you're doing the functions that are supposed to do something, make them return a pointer, that way the functions will have much more uses and make you look at those beautiful "void* search(int value)" lines
.