SphereCommunity
Function not Checking?! - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Function not Checking?! (/Thread-Function-not-Checking)



Function not Checking?! - Chukwuemeka - 11-11-2016 03:30 AM

Hey folks,
I'm editing a level system script and I'm getting a problem.

Code:
[FUNCTION f_levelup]
f_show_xp_title
IF (<TAG0.EXP> >= <TAG0.LEVELUP>)
   SYSMESSAGE @030 You gain a level!
    TAG0.EXP=0
    TAG0.LEVELUP += 1000
    TAG0.MYLEVEL += 1

When I use it with a player, it checks the TAG and works great.

Code:
ON=@DEATHCORPSE
REF1 = <ARGO.MORE2>

IF (<REF1.ISPLAYER>) && (<i.ISNPC>)
    LOCAL.EXP_GAIN=<EVAL ((<i.STR> + <i.DEX>)/5)>
    REF1.TAG0.EXP += <dLOCAL.EXP_GAIN>
    SAY @030 You gain <eval <dLOCAL.EXP_GAIN>> experience.
    REF1.f_levelup
    RETURN 0
ENDIF

Now, I want to make summons and pets give the player EXP. It says I got the right EXP, but I always level up.

Code:
IF (<REF1.FLAGS> & statf_pet) && (<REF1.ISNPC>) && (<i.ISNPC>)
LOCAL.EXP_GAIN=<EVAL ((<i.STR> + <i.DEX>)/5)>
TRY UID.<REF1.MEMORYFINDTYPE.memory_ipet.LINK>.tag0.exp += <EVAL <LOCAL.EXP_GAIN>>
    SAY @030 You gain <eval <dLOCAL.EXP_GAIN>> experience.
    TRY UID.<REF1.MEMORYFINDTYPE.memory_ipet.LINK>.f_levelup
    RETURN 0
ENDIF

It seems to be missing this check (<TAG0.EXP> >= <TAG0.LEVELUP>).
Where am I going wrong?

Thank you!


RE: Function not Checking?! - darksun84 - 11-11-2016 09:31 PM

Probably it's caused by the TRY command, when you use an operator like += Sphere does this:

x += y
x = <eval (x+y)>

So that TRY line becomes:

TRY UID.<REF1.MEMORYFINDTYPE.memory_ipet.LINK>.tag0.exp += <EVAL <LOCAL.EXP_GAIN>>

TRY UID.<REF1.MEMORYFINDTYPE.memory_ipet.LINK>.tag0.exp = <eval (<TRY <UID.<REF1.MEMORYFINDTYPE.memory_ipet.LINK>.tag0.exp> + <EVAL <LOCAL.EXP_GAIN>>)

Anyway, according to the Wiki the TRY is obsolete since 2006, so you can safely remove it.


RE: Function not Checking?! - ShiryuX - 11-12-2016 03:12 AM

Maybe you have to go basic at the start of the script.

Code:
ON=@DeathCorpse
if (!<uid.<argo.more2>.isplayer>)
  if <uid.<argo.more2>.memoryfindtype.memory_ipet>
  ref1 = <uid.<argo.more2>.memoryfindtype.memory_ipet.link>
  endif
else
ref1 = <argo.more2>
endif
// your normal gain code.

if your npcs gain level also, just put an "else" after setting the pet link as ref1.


RE: Function not Checking?! - Chukwuemeka - 11-13-2016 09:27 PM

Thanks a lot! TRY was indeed the problem.