problem with create actor

Non-platform specific questions.

problem with create actor

Postby DollMaster » Wed Sep 28, 2011 5:10 am

Code: Select all
CreateActor("menuequip", "menuequip", "(none)", "(none)", view.x+253, view.y+293, false);


Still working on my inventory system. I have this code on a key down event when the cursor interacts with an inventory slot containing armor(for this example, its the brown armor). I want another menu to pop up prompting the player to equip, or drop the item. It works fine when the cursor is in the initial position. However, when you try selecting the armor in a different inventory slot, it creates the actor in a different spot.

I thought the view.x and view.y coordinates are relative to the view. Or am I wrong?

I tried it with the TRUE tag at the end as well, but that creates it relative to game center i think. Does not work too well when I want it to appear at certain spot. Or am I doing this all wrong and should be using transparencies?
Attachments
menuinteraction3p1.zip
(74.93 KiB) Downloaded 100 times
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: problem with create actor

Postby skydereign » Wed Sep 28, 2011 5:20 am

Okay, if you use CreateActor, then when you specify false, that means relative to the actor that is creating the menuequip actor.
Code: Select all
CreateActor("menuequip", "menuequip", "(none)", "(none)", 100, 0, false);

The above code will create the actor 100 pixels to the right of the above script's event actor.

Code: Select all
CreateActor("menuequip", "menuequip", "(none)", "(none)", 100, 0, true);

This will create the actor in coordinate (100, 0), using true coordinates. That means it is 100 pixels to the right of the origin.

Code: Select all
CreateActor("menuequip", "menuequip", "(none)", "(none)", view.x, view.y, true);

This will create the actor at the view's position.

Of course if you use parenting on any of the actors, then results will be skewed.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: problem with create actor

Postby DollMaster » Wed Sep 28, 2011 6:55 am

What are the details of this scewing? My player actor is a parent of the view. I just changed the keydown event to a different stationary actor. And although the coordinates need some tweaking, I'm sure I can get it to look right.

Upon playing around with my new fix, and also on my other version, I noticed that I cannot pickup some of the clones. They are not destroyed, nor are they added to my inventory. This appears to be a bug in GE, as its only sometimes when you first load my game.

Also, I tried doing this one menu popup with transparencies, but for some reason, you change one, and all of them start to mess up and change.
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: problem with create actor

Postby EvanBlack » Thu Oct 06, 2011 8:00 pm

Hey! Your problem can be fixed simply by using nodes. If you create a list of center points with game coordinates or screen coordinates attached to each node, then you only have to retrieve the node you need at any point.

I am going to create a GUI system for my rpg game maker using screen nodes. It will bring menus up, buttons, allow for drag and drop of inventory items and even node snapping.

Check out my ISOMAP GENERATOR for examples of using nodes.

Here is the create map function that creates a square grid graph of nodes:

Code: Select all
void CreateMap()
{
//Variables for map creation
 int mh;
 int mw;

//temporary x,y
 int tX = 0;
 int tY = 0;

//number of tiles
 int tNum = 0;

// MAPHEIGHT is a const that gives the height of the grid, declared as a global variable
 for(mh = 0; mh < MAPHEIGHT; ++mh)
 {
// TILESIZE[] is a const array with the tiles length and width, declared as a global variable
// This formula gives you the center of each tile on the Y axis
     tY = (TILESIZE[0] * mh) + (TILESIZE[0]/2);

// MAPWIDTH is a const that gives the height of the grid, declared as a global variable
     for(mw = 0; mw < MAPWIDTH; ++mw)
     {
// This formula gives you the center of each tile on the X axis
         tX = (TILESIZE[1] * mw) + (TILESIZE[1]/2);

// Increases node X based on MAPWIDTH at the time of loop, tnum is the node ID
         NodeX[tNum] = mw;

// increases node Y based on MAPHEIGHT at the time of loop
         NodeY[tNum] = mh;

// This is node data used for the finding game or screen coordinates
         NodeID[tNum] = tNum;
         NodeX[tNum]  = tX;
         NodeY[tNum]  = tY;
         tNum = tNum +1;
     }
 }
 
 
}

//This is a 2D map creation loop. This will be used later to create the screen nodes.





That code doesn't link the nodes to the screen, but it can be used to link the nodes to the screen, you just have to add the extra code that makes the item go to the coordinates based off the node.

Basically:
Code: Select all
PSUEDOCODE:

// if X and Y match return the node
for(x= 0; clickedscreenX == NodeX[x]; ++x)
if( clickedscreenY == NodeY[x])
{    return NodeID[x]; }


Now that code won't ACTUALLY work, because you would have to click the center pixel of each tile area in order to get the exact x,y but you can find a different formula that searches within the TILESIZE[]. But, it gives you an idea of how you would do it.

Also for your transparency issue, have you tried using an Actor* variable to store the actor that you've created and then doing something like

Code: Select all

Actor* myActor;

myActor = CreateActor();

myActor->transp = 0.0;



Haven't used it, but it should work in theory.
(\__/) ( 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: problem with create actor

Postby skydereign » Thu Oct 06, 2011 8:28 pm

EvanBlack wrote:Also for your transparency issue, have you tried using an Actor* variable to store the actor that you've created and then doing something like

Code: Select all

Actor* myActor;

myActor = CreateActor();

myActor->transp = 0.0;



Haven't used it, but it should work in theory.

So you know, using CreateActor will set the default struct* to be the newly created one (just for the rest of the event). So if you used it to create the actor "actor", then you can use actor.variable instead of using the Actor*.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: problem with create actor

Postby EvanBlack » Thu Oct 06, 2011 10:13 pm

Err... can you explain that?

If myActor is the name of the actor created.

using : myActor.x Causes Error: Undefined myActor
using : myActor->x same error

Using Actor.myActor->x causes Error: Declaration error

_____________________________________________________

But using:

Actor* myActor;

myActor = CreateActor();

myActor->x Works, but only until the next call to CreateActor. Then my pointer is invaild, unless reassigned to the newly created actor.

myActor.x Causes Error: Illegal Structure Operation

______________________________________________________


Easier way to change transparency if you know the clone name of each open menu. Just use this function.

ChangeTransparency("myActor.0", 0.5);

If you want to use the same function, making it more dynamic, you can do this.

sprintf(cloneName, "myActor.%i", cloneindex);
ChangeTransparency(cloneName, 0.5);

or

ChangeTransparency(myActor->clonename, 0.5);
Last edited by EvanBlack on Thu Oct 06, 2011 10:54 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: problem with create actor

Postby skydereign » Thu Oct 06, 2011 10:53 pm

In that case, myActor would need to be the name of the actor. gE supports a default actor that can be accessed by script. Normally it is the lowest cloneindexed actor, but if you use CreateActor, anywhere after it will access the most recently created actor.
Code: Select all
actor.x+=5; // this will move the lowest cloneindexed actor 5 pixels
CreateActor("actor", "anim", "(none)", "(none)", 0, 0, true);
actor.x+=5; // this will move the actor that was just created


Of course you can't rely on this in global script (or using Actor*) since of a bug in gE. You have to make sure to add a reference to the actor in the event script.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: problem with create actor

Postby EvanBlack » Thu Oct 06, 2011 11:03 pm

myActor is the name of the actor in my game. I cannot use myActor.variable at all. It just gives me an error. Lowest index or not, it just will not at all work in my script.


BTW- by lowest index you mean 0 or next one up if 0 doesn't exist, and so on?

Basically.

myActor.0 <- Lowest indexed
myActor.1
myActor.2


Destory myActor.0

myActor.1 <- Lowest indexed
myActor.2
(\__/) ( 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: problem with create actor

Postby skydereign » Thu Oct 06, 2011 11:07 pm

Yes, that is what I mean by lowest cloneindex. But, of course you would need variable defined as an actor variable. So, replace it with transp or another actor variable and it should work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: problem with create actor

Postby EvanBlack » Thu Oct 06, 2011 11:26 pm

No thats what I mean... lol..

using this code doesn't work.

Code: Select all
void CreateandMove(int z)
{
    int X, Y;
    CreateActor("myActor", "Anim1", "no parent", "no path", 0, 0, false);
 
    for( X=z; X != z+3; ++X)
    {
        myActor.x = myActor.x + X;
        for( Y=z; Y != z+2; ++Y)
       {
        myActor.y = myActor.y + Y;
       }
    }
}



Gives Error: Illegal Structure Operation
(\__/) ( 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: problem with create actor

Postby skydereign » Thu Oct 06, 2011 11:33 pm

The code works fine for me. Of course, it may have problems actually running in game due to that bug I mentioned.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest