Page 1 of 1

Help please!

PostPosted: Sun Aug 28, 2011 10:35 am
by HitoV
First off hello! My first post here woot woot! :p Anyhoo, I have been addicted to gE for about 2 weeks now. Ive read up and down the tutorials and forums post. I have very basic knowledge programming. I was wondering if someone could help me. What I would like to do is have a char passed into an existing function. Say for example...


void example1()
{
CreateActor("smoke", "smoke", "(none)", "(none)", rand(width)-width/2, rand(height)-height/2, false);
}



Thats all fine and dandy but what if I want it to do a different animation sequence like this...

void example2(char myString[255])
{
CreateActor("smoke", "myString[255]", "(none)", "(none)", rand(width)-width/2, rand(height)-height/2, false);
}


Obviously it does not execute properly nor does it take in the correct colors that "acknowledge" it when writing it. Is there a way to do this? I have looked in several places for proper syntax and have come up empty handed so far. I would greatly appreciate any help! Thanks!!

Re: Help please!

PostPosted: Sun Aug 28, 2011 11:04 am
by skydereign
The function would look like this.
Code: Select all
void example2(char myString[255])
{
    CreateActor("smoke", myString, "(none)", "(none)", rand(width)-width/2, rand(height)-height/2, false);
}


For some background, the char myString[255] declares an array of chars, which together form a string In the first line, you can see that you declared a char array called myString, which means you can use myString in the scope of the function. So, you are able to type myString, like in the above code, without getting any errors. The reason you don't put it in double quotes is that anything within the double quotes is a const char * (so it thinks you literally mean to change the animation to "myString[255]", instead of replacing it with the contents of myString). Lastly, you don't put the [255], as you aren't declaring the variable (as you already did that), myString[255] is out of the array bounds, and myString[0] (or any other index between 0 and 254) will return a single character, and not the string. So, typing just myString will combine all of the chars in the array to form the string.

Re: Help please!

PostPosted: Sun Aug 28, 2011 10:27 pm
by HitoV
Holy crud! It was a newby mistake after all! :(
Thanks a billion my friend! I understand it very well now because of your explanation. I tried to plus but I need more post so hopefully this one will count :D

Now skies the limits!!!!

Re: Help please!

PostPosted: Thu Sep 01, 2011 2:01 am
by HitoV
Poop, i need help again.. if someone could help me I'd really appreciate it!

What I am trying to do is this: (focus is on yvelocity)
Code: Select all
void spawn(char myString[30], int x, int y, int xv, int yv)
{
CreateActor(myString, "default", "(none)", "(none)", x, y, true);
mystring.yvelocity = p1s/yv;
}


Everything works great but the yvelocity. If I leave it blank it moves the creator automatically. Is there any way I can pass myString without the quotes, or is there a special actor call i can use to get it to move the created actor? This would really help me out a bunch! Thanks for your time!

Re: Help please!

PostPosted: Thu Sep 01, 2011 2:40 am
by skydereign
There is a way of passing actors, but you need to know how to use Actor*s. Use this code.
Code: Select all
void spawn(char myString[30], int x, int y, int xv, int yv)
{
    CreateActor(myString, "default", "(none)", "(none)", x, y, true)->yvelocity=p1s/yv;
}

CreateActor returns a pointer to the actor, which allows you to edit its values. Since it is a pointer to a struct, you use -> to access its contents (-> = points to). Since the created actor is the actor you wanted to change, the above is all you needed to do. If though you wanted to set two variables, you'd need to store the Actor*.

Re: Help please!

PostPosted: Thu Sep 01, 2011 11:00 am
by HitoV
Thanks so much sky! I would like to also define the xvelocity so it looks like I'll have to go the actor * route. I found a example of it so I should be able to decipher how exactly it works :D I'll try it out tomorrow, thanks again sky!