Help please!

Non-platform specific questions.

Help please!

Postby HitoV » Sun Aug 28, 2011 10:35 am

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!!
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score

Re: Help please!

Postby skydereign » Sun Aug 28, 2011 11:04 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Help please!

Postby HitoV » Sun Aug 28, 2011 10:27 pm

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!!!!
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score

Re: Help please!

Postby HitoV » Thu Sep 01, 2011 2:01 am

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!
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score

Re: Help please!

Postby skydereign » Thu Sep 01, 2011 2:40 am

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*.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Help please!

Postby HitoV » Thu Sep 01, 2011 11:00 am

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!
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest