Page 1 of 1

Suspicious pointer conversion

PostPosted: Sat Apr 14, 2012 8:48 pm
by phyzix5761
After an hour of searching and testing I decided to post this problem here. Maybe someone has a solution.

I am trying to create a clone of a certain actor named "grassTileSet". I have created a function that creates a random number and chooses an array index. I have placed that array index into an integer named nextTile. I want to use nextTile to define the second parameter of the CreateActor function. I get an error that says "suspicious pointer conversion" and the program won't execute when I try to run it. I have tried converting nextTile to a char but I guess I've been unsucessful. If anyone can give me some ideas, please help. Thanks!


Code: Select all
CreateActor("grassTileSet", nextTile, "(none)", "(none)", 32, 0, false);

Re: Suspicious pointer conversion

PostPosted: Sat Apr 14, 2012 8:55 pm
by foleyjo
Not too sure as I am having a similar issue myself but try looking at a method which uses getanimindex

getanimindex(nextTile)

Re: Suspicious pointer conversion

PostPosted: Sat Apr 14, 2012 9:02 pm
by phyzix5761
Unfortunately that won't work because the parameter it takes in the () is supposed to be the char name of an existing actor and my variable is an integer.


EDIT: getAnimName(nextTile) seems to work!

Re: Suspicious pointer conversion

PostPosted: Sat Apr 14, 2012 9:26 pm
by foleyjo
Not sure if your problem is the same but I've been trying to do a similar create actor even using a variable for the animation name

My command was

CreateActor("obj", getAnimName(ThisAnim), "(none)", "(none)", Player.x, Player.y, false);

where ThisAnim was the animation I wanted to use.
The problem was that I used this in a function from a different actor. So when I got the Animname I was getting the wrong animation.
Is this similar to what you are doing?

Re: Suspicious pointer conversion

PostPosted: Sat Apr 14, 2012 9:49 pm
by phyzix5761
I just had that problem. Make a new function that references the animation index your generated.

Something like this:

if(nextTile==2)
CreateActor("obj", "2", etc etc....)

The problem I was having is that it was creating the wrong animation so I had to reference it directly and this worked.

Re: Suspicious pointer conversion

PostPosted: Sun Apr 15, 2012 1:15 am
by skydereign
Trying to pass an integer value (nextTile) for a string is pretty suspicious. And getAnimName is currently rather limited, as it is one of the gE functions that doesn't support other actors. Instead of creating a function to create the actors, you can create a function that returns a string (the animation name).
Code: Select all
char*
getAnimName2 (char* aname, int index)
{
    if(strcmp(aname, "player")==0)
    {
        switch(index)
        {
            case 0:
            return "stand_right";
           
            case 1:
            return "stand_left";

            // and so on
        }
    }
    else if(strcmp(aname, "enemy")==0)
    {
        // and so on
    }
}

Of course using an indexing scheme for your actors means you can use nested switch statements instead of a lot of strcmps.

Re: Suspicious pointer conversion

PostPosted: Sun Apr 15, 2012 2:19 am
by phyzix5761
Thanks Sky!