[QUOTE=pyschomc;39633313]HOW SHOULD I APPROACH THIS?[/QUOTE]
With a debugger, so that you will know exactly which line and what instructions you wrote wrong.
-snip-
Hi!
I started to program in Python 2.7 just to learn the language a bit and now I ran into a problem.
Basically at the start I define a variable:
[CODE]session = "000000000000000000"[/CODE]
Then I start a thread:
[code]recv_thread=Thread(target=recv_from_srv)
recv_thread.start()[/code]
[code]def recv_from_srv():
while 1:
data = sock.recv(recv_length)
process_recv(data)
[/code]
And the session doesn't get updated even tough the print shows the corrct session id on the commandline:
[code]def process_recv(data):
data_split = data.split(":")
if len(data_split) < 1:
print "do nothing"
elif data_split[0] == "cmd" and len(data) > 1:
if data_split[1] == "setsess" and len(data) > 2:
session = data_split[2] ## <--- this doesn't work
print "Your session id is", data_split[2][/code]
Did I overlook something or is it just not possible to change the session variable?
So I am completely lost here, apparently the two lines with body:setPosition in them are both trying to use a nil variable.
It seems like the function can't access self.bBox and solf.bDot even though its in the same class. No idea why.
I'm not too familiar with Lua yet :x
[CODE]
require "console"
require "middleClass"
require "camera"
collisionMap = class("collisionMap")
lineCount = 1 --make these local!!!!!!
dotCounter = 1
boxCounter = 1
dotCounterU = 1
boxCounterU = 1
function collisionMap:initialize()
self.bBox = {}
self.bDot = {}
self.fileLine = {}
self.loaded = false
end
function collisionMap:LoadMap(mapFileName, World)
local i = 1
local file = io.open([[H:\]] .. mapFileName or mapFileName .. ".txt", "r")-- change this directory later
if file then
for line in file:lines() do
self.fileLine[i] = {}
self.fileLine[i].x, self.fileLine[i].y, self.fileLine[i].h, self.fileLine[i].w, self.fileLine[i].Type = unpack(split(line,","))
i = i + 1
end
lineCount = i-1
else
end
for i = 1,lineCount do
if tonumber(self.fileLine[i].h) ~= 1 then
self.bBox[boxCounter] = {}
self.bBox[boxCounter].body = love.physics.newBody(World,self.fileLine[i].x+(self.fileLine[i].w/2),self.fileLine[i].y+(self.fileLine[i].h/2))
self.bBox[boxCounter].shape = love.physics.newRectangleShape(0,0,self.fileLine[i].w,self.fileLine[i].h)
self.bBox[boxCounter].fixture = love.physics.newFixture(self.bBox[boxCounter].body,self.bBox[boxCounter].shape)
self.bBox[boxCounter].x = self.fileLine[i].x
self.bBox[boxCounter].y = self.fileLine[i].y
boxCounter = boxCounter + 1
else
self.bDot[dotCounter]={}
self.bDot[dotCounter].body = love.physics.newBody(World,self.fileLine[i].x,self.fileLine[i].y)
self.bDot[dotCounter].shape = love.physics.newRectangleShape(0,0,1,1)
self.bDot[dotCounter].fixture = love.physics.newFixture(self.bDot[dotCounter].body,self.bDot[dotCounter].shape)
self.bDot[dotCounter].x = self.fileLine[i].x
self.bDot[dotCounter].y = self.fileLine[i].y
dotCounter = dotCounter + 1
end
end
self.loaded = true
end
function collisionMap:translationUpdate()
if self.loaded then
for i = 1,lineCount do
if tonumber(self.fileLine[i].h) ~= 1 then
self.bBox[boxCounterU].body:setPosition(self.bBox[boxCounterU].x+TranslationX+(self.fileLine[i].w/2),self.bBox[boxCounterU].y+TranslationY+(self.fileLine[i].h/2))
boxCounterU = boxCounterU + 1
else
self.bDot[dotCounterU].body:setPosition(self.bDot[dotCounterU].x+TranslationX, self.bDot[dotCounterU].y+TranslationY)
self.bDot[dotCounterU].x = self.bDot[dotCounterU].body:getX()
self.bDot[dotCounterU].y = self.bDot[dotCounterU].body:getY()
dotCounterU = dotCounterU + 1
end
end
end
end
function collisionMap:DebugDraw()
if self.loaded then
for i=1,boxCounter do
love.graphics.polygon("line", self.bBox[i].body:getWorldPoints(self.bBox[i].shape:getPoints()))
end
for i=1,dotCounter do
love.graphics.point(self.bDot[i].x+TranslationX,self.bDot[i].y+TranslationY)
end
end
end
[/code]
[editline]19th February 2013[/editline]
Huh.. this was my 3000th post. Kind of a waste.
[QUOTE=reevezy67;39641788]So I am completely lost here, apparently the two lines with body:setPosition in them are both trying to use a nil variable.
It seems like the function can't access self.bBox and solf.bDot even though its in the same class. No idea why.
I'm not too familiar with Lua yet :x
[CODE]
require "console"
require "middleClass"
require "camera"
collisionMap = class("collisionMap")
lineCount = 1 --make these local!!!!!!
dotCounter = 1
boxCounter = 1
dotCounterU = 1
boxCounterU = 1
function collisionMap:initialize()
self.bBox = {}
self.bDot = {}
self.fileLine = {}
self.loaded = false
end
function collisionMap:LoadMap(mapFileName, World)
local i = 1
local file = io.open([[H:\]] .. mapFileName or mapFileName .. ".txt", "r")-- change this directory later
if file then
for line in file:lines() do
self.fileLine[i] = {}
self.fileLine[i].x, self.fileLine[i].y, self.fileLine[i].h, self.fileLine[i].w, self.fileLine[i].Type = unpack(split(line,","))
i = i + 1
end
lineCount = i-1
else
end
for i = 1,lineCount do
if tonumber(self.fileLine[i].h) ~= 1 then
self.bBox[boxCounter] = {}
self.bBox[boxCounter].body = love.physics.newBody(World,self.fileLine[i].x+(self.fileLine[i].w/2),self.fileLine[i].y+(self.fileLine[i].h/2))
self.bBox[boxCounter].shape = love.physics.newRectangleShape(0,0,self.fileLine[i].w,self.fileLine[i].h)
self.bBox[boxCounter].fixture = love.physics.newFixture(self.bBox[boxCounter].body,self.bBox[boxCounter].shape)
self.bBox[boxCounter].x = self.fileLine[i].x
self.bBox[boxCounter].y = self.fileLine[i].y
boxCounter = boxCounter + 1
else
self.bDot[dotCounter]={}
self.bDot[dotCounter].body = love.physics.newBody(World,self.fileLine[i].x,self.fileLine[i].y)
self.bDot[dotCounter].shape = love.physics.newRectangleShape(0,0,1,1)
self.bDot[dotCounter].fixture = love.physics.newFixture(self.bDot[dotCounter].body,self.bDot[dotCounter].shape)
self.bDot[dotCounter].x = self.fileLine[i].x
self.bDot[dotCounter].y = self.fileLine[i].y
dotCounter = dotCounter + 1
end
end
self.loaded = true
end
function collisionMap:translationUpdate()
if self.loaded then
for i = 1,lineCount do
if tonumber(self.fileLine[i].h) ~= 1 then
self.bBox[boxCounterU].body:setPosition(self.bBox[boxCounterU].x+TranslationX+(self.fileLine[i].w/2),self.bBox[boxCounterU].y+TranslationY+(self.fileLine[i].h/2))
boxCounterU = boxCounterU + 1
else
self.bDot[dotCounterU].body:setPosition(self.bDot[dotCounterU].x+TranslationX, self.bDot[dotCounterU].y+TranslationY)
self.bDot[dotCounterU].x = self.bDot[dotCounterU].body:getX()
self.bDot[dotCounterU].y = self.bDot[dotCounterU].body:getY()
dotCounterU = dotCounterU + 1
end
end
end
end
function collisionMap:DebugDraw()
if self.loaded then
for i=1,boxCounter do
love.graphics.polygon("line", self.bBox[i].body:getWorldPoints(self.bBox[i].shape:getPoints()))
end
for i=1,dotCounter do
love.graphics.point(self.bDot[i].x+TranslationX,self.bDot[i].y+TranslationY)
end
end
end
[/code]
[editline]19th February 2013[/editline]
Huh.. this was my 3000th post. Kind of a waste.[/QUOTE]
It isn't a waste as long as you learn something from it :)
Sadly I haven't had much experience with lua, only derping around in garrys mod with it. Could it be because you are using the dot operater instead of the colon? when I was programming in lua I seem to recall using : to get variables from stuff.
self:bdot?
Another guess I have is because the variable is not initialized with a default value. But I doubt that is the problem.
[QUOTE=Duskling;39643148]It isn't a waste as long as you learn something from it :)
Sadly I haven't had much experience with lua, only derping around in garrys mod with it. Could it be because you are using the dot operater instead of the colon? when I was programming in lua I seem to recall using : to get variables from stuff.
self:bdot?
Another guess I have is because the variable is not initialized with a default value. But I doubt that is the problem.[/QUOTE]
The colon operator is for method calling (it is just syntactic sugar for obj.method(obj, ...), not for accessing table values.
[QUOTE=reevezy67;39641788]So I am completely lost here, apparently the two lines with body:setPosition in them are both trying to use a nil variable.
It seems like the function can't access self.bBox and solf.bDot even though its in the same class. No idea why.
I'm not too familiar with Lua yet :x
-snip-
[editline]19th February 2013[/editline]
Huh.. this was my 3000th post. Kind of a waste.[/QUOTE]
Can you post the exact error?
I am having trouble with textures in opengl. For some reason, the texture, on the Y, is getting cut off and it is only drawing a certain bit of the texture. It's strange. I have tried changing the filter and the width/height, but I can't figure out the problem.
The red highlighted bit is what is drawing.
[T]http://i.imgur.com/Ee3zfjI.png[/T]
EDIT:
Figured it out. was doing this:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_RGB, GL_BYTE, buf );
Instead of this:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tWidth, tHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf );
what is the difference between unsigned byte and regular byte?
[QUOTE=Duskling;39644129]I am having trouble with textures in opengl. For some reason, the texture, on the Y, is getting cut off and it is only drawing a certain bit of the texture. It's strange. I have tried changing the filter and the width/height, but I can't figure out the problem.
The red highlighted bit is what is drawing.
[T]http://i.imgur.com/Ee3zfjI.png[/T]
EDIT:
Figured it out. was doing this:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_RGB, GL_BYTE, buf );
Instead of this:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tWidth, tHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf );
what is the difference between unsigned byte and regular byte?[/QUOTE]
I don't know what it means in your case, but an unsigned byte can hold a greater (2^8) value but doesnt support negatives and signed bytes hold lower value(2^7) but does support negatives.
[QUOTE=Joker169;39645645]I don't know what it means in your case, but an unsigned byte can hold a greater (2^8) value but doesnt support negatives and signed bytes hold lower value(2^7) but does support negatives.[/QUOTE]
Thanks :)
Im trying to make a 2D tennis game, working on the ball 'physics' right now. Dont know how i will calculate it to make simulate moving in 3D ( moving in an arc ). im assuming i need a 3D Vector to do the math on? anyone have any useful links?
[QUOTE=Tortex;39647642]Im trying to make a 2D tennis game, working on the ball 'physics' right now. Dont know how i will calculate it to make simulate moving in 3D ( moving in an arc ). im assuming i need a 3D Vector to do the math on? anyone have any useful links?[/QUOTE]
probably just a form of y = -x² for a rudimentary arc simulation
[QUOTE=Tortex;39647642]Im trying to make a 2D tennis game, working on the ball 'physics' right now. Dont know how i will calculate it to make simulate moving in 3D ( moving in an arc ). im assuming i need a 3D Vector to do the math on? anyone have any useful links?[/QUOTE]
What you're looking for is projectile physics.
The best "tutorial" I could find was this : [url]http://www.physicsclassroom.com/class/vectors/u3l2e.cfm[/url]
It's only in 2d but that's okay for a tennis ball trajectory.
[QUOTE=MakeR;39643442]
Can you post the exact error?[/QUOTE]
collisionMap.lua:59: attempt to index field '?' (a nil value)
[editline]20th February 2013[/editline]
Sorry for the late reply I was asleep.
[QUOTE=Tortex;39647642]Im trying to make a 2D tennis game, working on the ball 'physics' right now. Dont know how i will calculate it to make simulate moving in 3D ( moving in an arc ). im assuming i need a 3D Vector to do the math on? anyone have any useful links?[/QUOTE]
If you don't want to calculate the entire arc, you could just simulate ball as a particle and apply some basic mechanics to it, like this:
[cpp]if(ballHit) ballVelocity = someAmount; // Give it whatever velocity vector you calculate from the hit.
// Later on
ballVelocity += gravity;
ballPosition += ballVelocity;[/cpp]
By adding on gravity to the velocity like that, and then adding velocity onto the position each frame, you will simulate a fairly correct arc for the ball.
I have a GLSL problem here. I'm trying to write a cube map reflection shader, but it's not going well. Here's what I have so far:
[code]vec3 eye_normal = (view_matrix * vec4(normal, 0.0)).xyz;
vec3 eye_pos = normalize(var_position.xyz / var_position.w);
vec4 reflected = view_inv_matrix * vec4(reflect(eye_pos, eye_normal), 0.0);
out_frag_colour = texture(skybox, normalize(reflected.xyz));[/code]
Here, 'normal' is the surface normal at this fragment, 'var_position' is the fragment's position in eye-space, and 'view_matrix' (and 'view_inv_matrix') is the camera's view transformation matrix (and its inverse).
This is what I get at the moment:
[t]http://puu.sh/25iGp[/t]
Are there any obvious things I've done wrong?
How do I make the cout command to output "true"?
[cpp]
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream wad("doom.wad", fstream::binary);
char* attributeName[15] = {"THINGS\0\0", "LINEDEFS", "SIDEDEFS", "VERTEXES", "SEGS\0\0\0\0", "SSECTORS", "NODES\0\0\0", "SECTORS\0",
"REJECT\0\0", "BLOCKMAP", "GL_VERT\0", "GL_SEGS\0", "GL_SSECT", "GL_NODES", "GL_PVS\0\0"};
char nextString[8];
wad.seekg(12376556);
wad.read(nextString, 8);
cout << (attributeName[6] == nextString);
return 0;
}
[/cpp]
Or, add this before your cout call:
[cpp]cout << boolalpha;[/cpp]
It will tell cout to automatically print booleans as "true" or "false" until you cancel it by sending noboolalpha.
Reference: [i][url]http://www.cplusplus.com/reference/ios/boolalpha/[/url][/i]
The fundamental issue is that booleans are implicitly castable to integers.
And because the C++ people think you might actually [I]want[/I] that, they make you use the [url=http://www.cplusplus.com/reference/ios/boolalpha/]std::boolalpha[/url] manipulator to make them output as "true" and "false".
(The manipulator works like std::endl. I trust you can use it.)
[editline]20th February 2013[/editline]
Aaaand I'm late. Bloody hell.
[QUOTE=Gulen;39649523][cpp]if(attributeName[6] == nextString)
cout << "true" << endl;
[/cpp][/QUOTE]
[QUOTE=ShaunOfTheLive;39649554]Or, add this before your cout call:
[cpp]cout << boolalpha;[/cpp]
It will tell cout to automatically print booleans as "true" or "false" until you cancel it by sending noboolalpha.
Reference: [i][url]http://www.cplusplus.com/reference/ios/boolalpha/[/url][/i][/QUOTE]
[QUOTE=esalaka;39649598]The fundamental issue is that booleans are implicitly castable to integers.
And because the C++ people think you might actually [I]want[/I] that, they make you use the [url=http://www.cplusplus.com/reference/ios/boolalpha/]std::boolalpha[/url] manipulator to make them output as "true" and "false".
(The manipulator works like std::endl. I trust you can use it.)
[editline]20th February 2013[/editline]
Aaaand I'm late. Bloody hell.[/QUOTE]
Um. I think you guys misinterpreted what I said.
I want the condition to be true in as little verbose a way as possible, not for cout to specifically output, "true".
As my program stands, the first 8 characters are similar, but when I see if they equal each other, I get a "false".
Also, in more complicated programs, you might wish to store the previous flags and restore them after use. This can be done with std::ios_base::fmtflags flags() which is used like so:
[code]
std::ios_base::fmtflags cout_flags = std::cout.flags();
// Do your own manipulation and printing here
std::cout.flags(cout_flags); // Reset flags to their earlier state
[/code]
[editline]20th February 2013[/editline]
Oh, well, in that case you have to use strcmp from <cstring> or cast one of the C-strings into a std::string which will make the == operator work as expected.
Currently, you're comparing two pointers.
[editline]20th February 2013[/editline]
Basically, you are either entering the hell that is C string handling, or you're entering the hell that is C++ string handling. Granted, the latter is a bit easier to handle.
[QUOTE=elevate;39649639]Um. I think you guys misinterpreted what I said.
I want the condition to be true in as little verbose a way as possible, not for cout to specifically output, "true".
As my program stands, the first 8 characters are similar, but when I see if they equal each other, I get a "false".[/QUOTE]
You're comparing a single char value with a pointer to a char.
Either use std::string, which allows you compare using the "==" operator, or if you must use c-strings then look into the strcmp() function.
[editline]20th February 2013[/editline]
Esa you are literally the worst.
[sp]love you really[/sp]
[QUOTE=esalaka;39649658]Oh, well, in that case you have to use strcmp from <cstring> or cast one of the C-strings into a std::string which will make the == operator work as expected.
Currently, you're comparing two pointers.
[editline]20th February 2013[/editline]
Basically, you are either entering the hell that is C string handling, or you're entering the hell that is C++ string handling. Granted, the latter is a bit easier to handle.[/QUOTE]
Thanks, strcmp() worked.
Also, I prefer to use C strings unless using a C++ string would really be necessary, as adding <string> adds more bulk to the program, I believe?
Also, I find it makes my programs less verbose since a lot of functions take C string parameters.
[QUOTE=elevate;39649823]Thanks, strcmp() worked.
Also, I prefer to use C strings unless using a C++ string would really be necessary, as adding <string> adds more bulk to the program, I believe?
Also, I find it makes my programs less verbose since a lot of functions take C string parameters.[/QUOTE]
I'd say you're probably optimising in the wrong places, std::string can save you a lot of trouble in certain situations.
As for passing it to functions, I wouldn't say adding a ".c_str()" on the end detracts from verbosity.
Yelp my foreign key won't work :/
[code]ALTER TABLE `Kinderentabel` ADD CONSTRAINT `ouderid` FOREIGN KEY (`KindID`) REFERENCES `Personeelsleden` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION;[/code]
Database structure:
[code]/*
Navicat MySQL Data Transfer
Source Server : localhost_3306
Source Server Version : 50524
Source Host : localhost:3306
Source Database : generic
Target Server Type : MYSQL
Target Server Version : 50524
File Encoding : 65001
Date: 2013-02-20 13:59:29
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `kinderentabel`
-- ----------------------------
DROP TABLE IF EXISTS `kinderentabel`;
CREATE TABLE `kinderentabel` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`KindID` int(11) DEFAULT '0',
`Geboortedatum` date DEFAULT NULL,
`Naam` varchar(255) DEFAULT NULL,
`Geslacht` char(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `ID` (`ID`),
KEY `KindID` (`KindID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of kinderentabel
-- ----------------------------
INSERT INTO `kinderentabel` VALUES ('2', '2', '1999-01-01', 'Carla Hendriks', 'V');
INSERT INTO `kinderentabel` VALUES ('3', '3', '2000-05-24', 'Jantje Klaasen', 'M');
INSERT INTO `kinderentabel` VALUES ('4', '3', '2001-06-24', 'Trudie Klaasen', 'V');
INSERT INTO `kinderentabel` VALUES ('5', '4', '2006-12-23', 'Mientje Stuntelaar', 'V');
-- ----------------------------
-- Table structure for `personeelsleden`
-- ----------------------------
DROP TABLE IF EXISTS `personeelsleden`;
CREATE TABLE `personeelsleden` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Naam` varchar(255) NOT NULL,
`Geboortedatum` date NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of personeelsleden
-- ----------------------------
INSERT INTO `personeelsleden` VALUES ('1', 'Piet Hendriks', '1970-06-15');
INSERT INTO `personeelsleden` VALUES ('2', 'Jan Klaasen', '1967-09-03');
INSERT INTO `personeelsleden` VALUES ('3', 'Klaas Jan Stuntelaar', '1983-08-12');
[/code]
Any idea why it refuses to make the foreign key?
:/
After some googling, I think it might be that it should be
[code]ALTER TABLE 'Kinderentable' ADD FOREIGN KEY ('KindID') REFERENCES 'Personeelsleden'('ID')[/code]
[QUOTE=Gulen;39654906]After some googling, I think it might be that it should be
[code]ALTER TABLE 'Kinderentable' ADD FOREIGN KEY ('KindID') REFERENCES 'Personeelsleden'('ID')[/code][/QUOTE]
Didn't work :/
It executed successfully but it doesn't show up in the foreign keys
[QUOTE=Mega1mpact;39654941]Didn't work :/
It executed successfully but it doesn't show up in the foreign keys[/QUOTE]
If it executed it's gotta be there.
[editline]20th February 2013[/editline]
[QUOTE=Mega1mpact;39654715]Yelp my foreign key won't work :/
[code]ALTER TABLE `Kinderentabel` ADD CONSTRAINT `ouderid` FOREIGN KEY (`KindID`) REFERENCES `Personeelsleden` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION;[/code]
Any idea why it refuses to make the foreign key?
:/[/QUOTE]
I believe this is SQL syntax, not MySQL syntax.
Nope, SQL and MySQL syntax is the same (at least here) this seems more like Oracle.
[QUOTE=Gulen;39655124]Nope, SQL and MySQL syntax is the same (at least here) this seems more like Oracle.[/QUOTE]
I used MySQL in college before, and I was taught to add foreign keys the way you just did.
Switched college, am now required to use SQL and adding foreign keys was demonstrated in the way mega did. Just assumed there was a difference in syntax bit it appears both are valid SQL and his first statement should have worked as well. I think,
Sorry, you need to Log In to post a reply to this thread.