Page 1 of 1

Reading arrays or animpos of a clone

PostPosted: Mon Sep 12, 2011 3:04 am
by DollMaster
I have a 2 wide 10 high inventory system set up, thanks to the tutorials. I also have a cursor moving around with the keyboard. But I don't know how to read what item is under the cursor.

1)How would I read animpos of a clone?

2)How would I read the arrays position of a clone?

More questions to come as it gets created more! I have a good feeling about this. lol

, key opens inventory
shift swings sword.

Re: Reading arrays or animpos of a clone

PostPosted: Mon Sep 12, 2011 3:57 am
by skydereign
For both of these you need to know about Actor*. For getting a clone, if there are no actors above it, you can use getactor to get the Actor* of the clone. For instance in your game, add this event to your menucursor actor.
menucursor -> Key Down X (repeat disabled) -> Script Editor
Code: Select all
getactor(x,y)->r=0;

That uses getactor to set the r value of the actor to 0. You can use the same function to get animpos.
Code: Select all
if(getactor(x,y)->animpos==0)
{
    //
}

I'd suggest though using a position indexing scheme. You have a variable holding the position in the array. So when you move to the right column, it increases it by one, while moving down increases it by 2. If you edit the events, you can keep the cursor in bounds of the inventory, as well as use it to get the cloneindex of the actor (so you can insert items).

Re: Reading arrays or animpos of a clone

PostPosted: Tue Sep 27, 2011 11:20 pm
by DollMaster
skydereign wrote:For both of these you need to know about Actor*. For getting a clone, if there are no actors above it, you can use getactor to get the Actor* of the clone. For instance in your game, add this event to your menucursor actor.
menucursor -> Key Down X (repeat disabled) -> Script Editor
Code: Select all
getactor(x,y)->r=0;

That uses getactor to set the r value of the actor to 0. You can use the same function to get animpos.
What am I setting the value to 0?
Code: Select all
if(getactor(x,y)->animpos==0)
{
   
}

Is this essentially saying, "if the animation position of the actor at x,y is 0, then finish code"?


Thank you for your reply, but I am still having trouble understanding. What does the operator '->' mean? Is that a nifty way of saying to set the value to the variable 'r'? I also have trouble with syntax, as you can see. My questions are in red. If the code you gave me means what I think it means, then it should be clear sailing from here.=)

Re: Reading arrays or animpos of a clone

PostPosted: Tue Sep 27, 2011 11:36 pm
by skydereign
Okay, first off the getactor function returns an Actor*. If you aren't familiar with pointers, all it is is a bit of memory that points to the place where an actor is stored. When dealing with an Actor*, you need to use the -> operator to follow where the pointer is pointing to, that way you can access the actors' variables. Said as simply as possible, all it is is a variable.
All the following code does is set the animpos of actor in position (x,y), to 0.
Code: Select all
getactor(x,y)->animpos = 0;


So, all that if statement does is check if the actor's animpos is 0.

Re: Reading arrays or animpos of a clone

PostPosted: Wed Sep 28, 2011 2:03 am
by DollMaster
Holy crap! Thank you so much! It appears to be working! I can figure it out from here! I think...