Jump to content

Photo

In Global Script how do I code if Sword 1 is in inventory


  • Please log in to reply
5 replies to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

  • Members
  • Real Name:Jason
  • Location:North America

Posted 23 June 2018 - 01:57 AM

I prefer coding help like
if (Link->X == 50){  Link->X = random(135);}
please, thank you.



How do I in a global script code both of the following 3:


#1: If Item Selector in inventory is at x position 168 and Y position 96


#2: If Item Selector is choosing Sword 1 Item as a selected item?


#3: If Sword 1 is in inventory

Edited by LikeLike888, 23 June 2018 - 01:59 AM.


#2 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 23 June 2018 - 03:32 AM

#3

if (Link->Item[I_SWORD1] == true)
{
//do stuff
}


#3 LikeLike888

LikeLike888

    Spicy food lover!!

  • Members
  • Real Name:Jason
  • Location:North America

Posted 23 June 2018 - 04:15 AM

Thank you @Binx

#4 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 23 June 2018 - 10:31 AM

There's no way to access the item selector from a script. You can use GetEquipmentA() and GetEquipmentB() from std.zh to get the currently selected items.
If you know the layout of the subscreen, you can guess the X and Y position of the selector based on what item is selected, but there's not a whole lot you can do with that information. Scripts don't run while the subscreen is open. If you want a scripted subscreen, you have to write your own from scratch.
 

if (Link->Item[I_SWORD1] == true)

Just want to point out that if(Link->Item[I_SWORD1]) would do exactly the same thing. x==y evaluates to either true or false, so true==true is the same as just true.

#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 23 June 2018 - 10:58 AM

 

#3

if (Link->Item[I_SWORD1] == true)
{
//do stuff
}

 

I'm pretty sure that won't compile in 2.50.2 and earlier. I recall fixing a parser issue where the internal getter for Link->Item was set to TYPE_FLOAT...

 

It it gives you an error, use::

if ( Link->Itemid] )
//or
if (!Link->Item[id])


#6 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 23 June 2018 - 01:50 PM

I'm pretty sure that won't compile in 2.50.2 and earlier. I recall fixing a parser issue where the internal getter for Link->Item was set to TYPE_FLOAT...

What? Why? That's how I always check items.

Just want to point out that if(Link->Item[I_SWORD1]) would do exactly the same thing. x==y evaluates to either true or false, so true==true is the same as just true.


I actually knew that, but I do it for organization's sake. The less code I have to mentally translate while I'm reading it, the better for my mental health while I'm trying to bugtest. It's a lot easier to miss an "!" than it is to mix up "true" and "false"

Edited by Binx, 25 June 2018 - 01:00 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users