Reading arrays or animpos of a clone

Non-platform specific questions.

Reading arrays or animpos of a clone

Postby DollMaster » Mon Sep 12, 2011 3:04 am

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.
Attachments
menuinteraction.zip
(99.93 KiB) Downloaded 77 times
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: Reading arrays or animpos of a clone

Postby skydereign » Mon Sep 12, 2011 3:57 am

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

Re: Reading arrays or animpos of a clone

Postby DollMaster » Tue Sep 27, 2011 11:20 pm

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.=)
Attachments
menuinteraction2.rar
(95.65 KiB) Downloaded 68 times
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: Reading arrays or animpos of a clone

Postby skydereign » Tue Sep 27, 2011 11:36 pm

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

Re: Reading arrays or animpos of a clone

Postby DollMaster » Wed Sep 28, 2011 2:03 am

Holy crap! Thank you so much! It appears to be working! I can figure it out from here! I think...
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest