Programming Thread

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

0 Members and 1 Guest are viewing this topic.

Legend

Quote from: the-Pi-guy on Dec 15, 2017, 03:39 PMWorking on an assignment due tonight.

I have a variable that is being changed between print statements, despite the fact the only time that variable gets changed is when it gets set originally.
I just had an issue like that!

In c# I replaced the variable with a function that acted like a variable. Then it could print a message everytime it was changed and tell me who changed it. Does c++ have similar?

the-pi-guy

#181
Quote from: Legend on Dec 16, 2017, 12:58 AMI just had an issue like that!

In c# I replaced the variable with a function that acted like a variable. Then it could print a message everytime it was changed and tell me who changed it. Does c++ have similar?

I think it's possible to have a pointer variable, that points to a function. 
Never tried it, but I recall reading something about it. 


Quote from: Legend on Dec 16, 2017, 12:58 AMI just had an issue like that!

In c# I replaced the variable with a function that acted like a variable. Then it could print a message everytime it was changed and tell me who changed it. Does c++ have similar?
I've been messing around some more. 

For some reason, this method is changing the value.  literally one line:
int getSize(int i)
return list[i].size;

the-pi-guy

Quote from: Legend on Dec 16, 2017, 12:58 AMI just had an issue like that!

In c# I replaced the variable with a function that acted like a variable. Then it could print a message everytime it was changed and tell me who changed it. Does c++ have similar?
So what the assignment is, is to implement malloc (memory allocation).
But it requires a data structure to keep track of data locations.  

I was using an array that would change length, by getting reassigned basically.  

But apparently assigning the arrays that way has some unusual behaviors.  

I changed all the declarations to utilizing malloc, which feels wrong.  Now it works great.  

It's apparently fine if the data structure uses malloc, but eh I don't like it.  

darkknightkryta

#183
Quote from: the-Pi-guy on Dec 16, 2017, 02:26 AMI think it's possible to have a pointer variable, that points to a function.  
Never tried it, but I recall reading something about it.  

I've been messing around some more.  

For some reason, this method is changing the value.  literally one line:
int getSize(int i)
return list[i].size;
Yes you can make a variable point to a function.  I vaguely recall it being in a lab.  Not sure why'd you would use it.

Quote from: the-Pi-guy on Dec 16, 2017, 03:53 PMSo what the assignment is, is to implement malloc (memory allocation).
But it requires a data structure to keep track of data locations.  

I was using an array that would change length, by getting reassigned basically.  

But apparently assigning the arrays that way has some unusual behaviors.  

I changed all the declarations to utilizing malloc, which feels wrong.  Now it works great.  

It's apparently fine if the data structure uses malloc, but eh I don't like it.  
Memory related issues are the hardest to debug.  C's memory system isn't that good either (Was at the time I guess).  Though as I tell all my students "Be kind to C and C will be kind to you"  So use malloc and like it :P

the-pi-guy

Quote from: darkknightkryta on Dec 16, 2017, 06:56 PMYes you can make a variable point to a function.  I vaguely recall it being in a lab.  Not sure why'd you would use it.
Memory related issues are the hardest to debug.  C's memory system isn't that good either (Was at the time I guess).  Though as I tell all my students "Be kind to C and C will be kind to you"  So use malloc and like it :P

How can I use malloc if I'm trying to implement malloc?  

darkknightkryta

Quote from: the-Pi-guy on Dec 16, 2017, 07:18 PMHow can I use malloc if I'm trying to implement malloc?  

Implement malloc?  You have to inline assembly for that...

Legend

#186
I'm having a stupid thing and I don't understand.

In Unity objects have a forward vector, a right vector, and an up vector. These are the calculus kind, not the c++ kind. I have a custom vector that's defined by a quaternion*vector, then multiplied by the object's rotation.

Something is screwing up because through testing I've realised that even if an object has two of these custom vectors defined, it can be in multiple rotations. Should be mathematically impossible but I really don't understand where my mistake is. Visually my custom vectors seem to function properly.

edt: figured it out!!!!!!!! my custom vectors were 180 degrees opposite of eachother so the system had issues. I should have checked on that possibility sooner.

edt2: well now it's not creating the full amount of vectors! I shouldn't program when this tired...

the-pi-guy

What do you mean multiple rotations?  Why is it impossible?

Legend

Quote from: the-Pi-guy on Dec 20, 2017, 04:37 AMWhat do you mean multiple rotations?  Why is it impossible?
If you define an object's forward direction and it's upwards direction, then you've fully defined its rotation. There is only one state it can be in. My forward and upward directions were accidentally opposite so the second vector didn't actually define anything new.

the-pi-guy

#189
Pi created his first server!

It plays a code breaking game with a client.
It's cool.

Legend

Quote from: the-Pi-guy on Feb 02, 2018, 03:56 AMPi created his first server!

It plays a code breaking game with a client.
It's cool.
So are you hosting it?

the-pi-guy

Quote from: Legend on Feb 02, 2018, 12:05 PMSo are you hosting it?
Well the server and the client are both being run on the same machine.  

Right now it's only set up to take one client, and then it shuts down.  

darkknightkryta

Yeah I need to get back into figuring out server programming.  I need to make my "gameification" of learning.  I have a whole JRPG idea for going through lessons and completing quizzes.  Gonna take me a while though.

the-pi-guy

Next server is multithreaded!
Many threads. Many clients.

the-pi-guy

#194
Quote from: Legend on Feb 02, 2018, 12:05 PMSo are you hosting it?
It seems to be as easy as changing the hostname in the server program to be able to do it over the internet.  

Would someone like to try?  :D

Actually maybe it doesn't work yet.  

I'm not sure how much of my errors is because something isn't set up right or because the computers aren't allowing it on campus.  

And I'm not sure how much trouble I could get into.