I'm using a line of code I don't fully understand and it's bugging me. [SOLVED]

Started by Darius Poyer, Sun 20/06/2010 13:28:44

Previous topic - Next topic

Darius Poyer

for rein I created a dynamic cursor that changes the mouse.Mode depending on what's underneath it. To add a check weather or not an item is at the mouse position I used this... variable?

Code: ags
InventoryItem*item=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);


in this function

Code: ags
function repeatedly_execute() 
{

if (invlength != 0){
  invx = invlength*20;
}
invpos=320-invx;
Inventory.X = invpos; //don't mind this, its juts part of my inventory display

InventoryItem*item=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);


     if (GetLocationType(mouse.x,mouse.y) == eLocationCharacter && cValery.ActiveInventory == null){
        mouse.Mode = eModeTalkto;
        }
     if (GetLocationType(mouse.x,mouse.y) == eLocationHotspot && cValery.ActiveInventory == null){
        mouse.Mode = eModeInteract;
        }
     if (GetLocationType(mouse.x,mouse.y) == eLocationObject && cValery.ActiveInventory == null){
        mouse.Mode = eModeInteract;
        }
     if (GetLocationType(mouse.x,mouse.y) == eLocationNothing && cValery.ActiveInventory == null){
    
         if (item == null) {
           mouse.Mode = eModeWalkto;
         }
         else {
           mouse.Mode = eModeInteract;
         }
      }
}


I think it returns the script name of the item and in case there is none, it returns 'null' so I used it to check if there was "some item" under the mouse.

It's some kind of variable and I've seen similar types like GUI in the scumm verbcoin script:

Code: ags
Object*obj=Object.GetAtScreenXY(mouse.x, mouse.y);
Hotspot*htspt=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
Character*chr=Character.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem*item=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem *item2; //(special check)
GUIControl *control = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
GUI *guixy = GUI.GetAtScreenXY(mouse.x, mouse.y);


I'm curios to know what they are and how I could use them for something other than what I've used it for thus far. It really doesn't feel right using code i don't fully understand.

Khris

It's called "pointer". It's a variable, but unless like e.g. int or float, it doesn't hold a number but an InventoryItem.

Once you've assigned an InventoryItem to it, you can call all the available functions on it or access its members, much like it were an actual item.
You have to make sure it's pointing at something though, otherwise you'll get the famous "null pointer error".


SMF spam blocked by CleanTalk