Suspicious pointer conversion

Non-platform specific questions.

Suspicious pointer conversion

Postby phyzix5761 » Sat Apr 14, 2012 8:48 pm

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);
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Suspicious pointer conversion

Postby foleyjo » Sat Apr 14, 2012 8:55 pm

Not too sure as I am having a similar issue myself but try looking at a method which uses getanimindex

getanimindex(nextTile)
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Suspicious pointer conversion

Postby phyzix5761 » Sat Apr 14, 2012 9:02 pm

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!
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Suspicious pointer conversion

Postby foleyjo » Sat Apr 14, 2012 9:26 pm

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?
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Suspicious pointer conversion

Postby phyzix5761 » Sat Apr 14, 2012 9:49 pm

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.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Suspicious pointer conversion

Postby skydereign » Sun Apr 15, 2012 1:15 am

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

Re: Suspicious pointer conversion

Postby phyzix5761 » Sun Apr 15, 2012 2:19 am

Thanks Sky!
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron