Stupid Fun Video about pointers

Game Editor comments and discussion.

Stupid Fun Video about pointers

Postby EvanBlack » Sat Oct 15, 2011 5:38 am

I found this lol, wow, its about pointers in C. Hope it helps some of you XD

http://www.cs.stanford.edu/cslibrary/PointerFunC.avi


HitoV wrote:Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D

http://home.earthlink.net/~momotuk/pointers.pdf
Last edited by EvanBlack on Sat Oct 22, 2011 9:37 pm, edited 1 time in total.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Stupid Fun Video about pointers

Postby Game A Gogo » Sat Oct 15, 2011 1:12 pm

This is great! +1
It helped me understand what I already thought I understood even better :) thanks a lot!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Stupid Fun Video about pointers

Postby jimmynewguy » Sat Oct 15, 2011 1:37 pm

I kind of understand this a little better, I'm just not sure how it "helps" me all too much in GE :lol: I guess I just don't fully understand it's use. Never took a programming course or any of the sort, just learned GE from GE-ers and trail and error. Enlighten me!
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Stupid Fun Video about pointers

Postby Game A Gogo » Sat Oct 15, 2011 2:04 pm

Well I don't see a purpose in them yet, but I am not advanced enough to need to use them either!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Stupid Fun Video about pointers

Postby Hblade » Sat Oct 15, 2011 4:01 pm

Thanks Evan! :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Stupid Fun Video about pointers

Postby SuperSonic » Sat Oct 15, 2011 5:52 pm

Haha, this is funnyXD
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Stupid Fun Video about pointers

Postby EvanBlack » Sat Oct 15, 2011 7:33 pm

Pointers allow you to create things like linked lists and allow you to access data without making a copy of it by referencing it directly.

Pointers are the most useful thing ever especially for gamedev. You use pointers all the time in your games and probably don't even realize it.

Everytime you change a variable in an actor you are first using the actor pointer to access the actor structure.

CreateActor() and getclone() both return pointers to the Actor's data structure in memory.

You could create an actor that moves in the same x as another actor by using a pointer.

Code: Select all
double *p_x; // global pointer

//set the pointer to the address of the actors x,  & gets the memory address
p_x = &MyActor1->x;

//set the other actors x to the value of the first actor using the pointer, * dereferences the pointer
MyActor2->x = *p_x;




Here is an example.
Attachments
pointer example.rar
(182.21 KiB) Downloaded 103 times
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Stupid Fun Video about pointers

Postby jimmynewguy » Sat Oct 15, 2011 8:07 pm

:P Try dragging these ones around!
Attachments
pointer example.zip
(1.62 KiB) Downloaded 112 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Stupid Fun Video about pointers

Postby EvanBlack » Sat Oct 15, 2011 8:10 pm

HAHAHA Thats awesome. Really cool. I hope you guys understand the importance and use of pointers now XD
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Stupid Fun Video about pointers

Postby Jagmaster » Sun Oct 16, 2011 12:14 pm

Thanks for the video, I love claymations! This was funny!
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Stupid Fun Video about pointers

Postby HitoV » Tue Oct 18, 2011 11:01 pm

This is great! I understand how they work and what they do but I don't understand why you would use them over other ways of getting the same values... :?

In the example, you have draw event in myActor1 as x = *p_x;
Using:
x = myActor2.x;
in the same draw event gives you the same thing.

I don't really see a use for them except for maybe getting a private variable out of the scope of a class. (which of course means nothing in ge)

What I do find confusing is how p_x updates with the... umm... hold on, I think a light bulb went off :shock:
How does it update even though its called in create actor which is a one shot type!?! AHHH! So that is what you mean by "gets the address of x and assigns it to the pointer." It literally references directly from the memory.
Son of a gun that's cool! Thanks! And thanks for the video, that was hilarious and informative :D
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score

Re: Stupid Fun Video about pointers

Postby EvanBlack » Wed Oct 19, 2011 1:04 am

Yeah lol and there are many many more reasons to use pointers instead of variables. Such as if you want to access an array.

Say you have an array of like 5 Million integers and you need to pass that array to a function. Instead of copying that huge array you can just pass a reference to it like this.

Code: Select all
int Array[5000000];

void function(int* pIntegers)
{
     //do stuff
}


function(&Array);



There are really many many reasons to use pointers. You just have to be creative and think about what you can do with them.

And yes, the address is a memory address.

* = dereferences an address, or gets the information stored at an address in the memory.

& = reference address, or gets the address of the information stored in the memory.

You can even get the address of a pointer and assign it to a double pointer.


Code: Select all

int X;
int A;

int *pX; //my integer pointer

int **ppX; //my pointer to an integer pointer

int ***pppX; // my pointer to and integer pointer pointer

X = 3;

pX = &X;

ppX = &pX;

pppX = &ppX;


A = *pX;  // A = X

A == 3 // or A == X

A == **ppX // A == 3

***pppX = 22; // X = 22

pX = &A;

X == 22;

A == 3;

***pppX == 3; //pppX  points to ppX which points to pX which points to A which has the value of 3

***pppX = 55;

X == 22;

A == 55;



Kind of confusing when you start putting more layers on but also know that pointers can be dereferenced a more readable way.

Continuing from above:
Code: Select all

pppX->ppX->pX->A == 55;

(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Stupid Fun Video about pointers

Postby HitoV » Sat Oct 22, 2011 9:16 pm

Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D

http://home.earthlink.net/~momotuk/pointers.pdf
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score

Re: Stupid Fun Video about pointers

Postby EvanBlack » Sat Oct 22, 2011 9:36 pm

HitoV wrote:Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D


AWESOMELY GOOD STUFF!! There is even information in that I want to learn more about lol. The internet is a great resource for learning. If compiled into a better list then it would be the best.

I am going to post that link at the top
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest