Jump to content
  • 0

Script automatiicaly modifies @menu & other variables


Question

Posted (edited)

Hello Everyone,

I'm kind of stuck with something stupid. I'm trying to get an element out of an array, which works fine. but if I use an if else statement with a question mark operator, it changes the variable I wanted to use by the amount which was set were the statement true

((@menu == 4)?.@a$[@menu-4]@menu == 3)?.@a$[@menu-2]:.@a$[@menu])

for some reason if @menu is not equal to 4, it goes ahead and sets @menu-4(.@a$[@menu-4]). I have no idea why. I tried using getelementofarray instead but it still returns the same issue.

Cheers!

Edited by garet999

8 answers to this question

Recommended Posts

Posted

prontera,156,180,5    script    testest    100,{
   setarray .@a$, "one", "two", "three", "four";
   select "1:2:3:4";
//    dispbottom ( (@menu == 4)? .@a$[@menu-4] : (@menu == 3)? .@a$[@menu-2] : .@a$[@menu] ); // BUG
   if ( @menu == 4 )
       dispbottom .@a$[@menu-4];
   else if ( @menu == 3 )
       dispbottom .@a$[@menu-2];
   else
       dispbottom .@a$[@menu];
   close;
}

yeah I know rathena script engine sux ... I understand how you feel ... because I feel the same ...

http://www.eathena.ws/board/index.php?s=&showtopic=272063&view=findpost&p=1501026

In javascript and others serious language the script block at "0" and doesn't execute the rest of the condition, it's optimized ! In eathena it execute all things in the condition.
Posted (edited)

May we see the script? Or more of this section at least if its super large, I'm curious to see what values are being priduced into what I'm assuming is a 'select' function.

Also, have you tried putting it into generic if statements with temp labels just to test results?

EDIT: So Annie, you can only have one ? operator inline like that?

Edited by Vach
Posted (edited)

prontera,156,180,5	script	testest	100,{
setarray .@a$, "one", "two", "three", "four";
select "1:2:3:4";
//	dispbottom ( (@menu == 4)? .@a$[@menu-4] : (@menu == 3)? .@a$[@menu-2] : .@a$[@menu] ); // BUG
if ( @menu == 4 )
	dispbottom .@a$[@menu-4];
else if ( @menu == 3 )
	dispbottom .@a$[@menu-2];
else
	dispbottom .@a$[@menu];
close;
}

yeah I know rathena script engine sux ... I understand how you feel ... because I feel the same ...

http://www.eathena.w...dpost&p=1501026

In javascript and others serious language the script block at "0" and doesn't execute the rest of the condition, it's optimized ! In eathena it execute all things in the condition.

Honestly, this is half-correct.

eA and rA uses the pbs, so actually dynamic if statements must be put into a specific block of instance.

//dispbottom ( (@menu == 4)? .@a$[@menu-4] : (@menu == 3)? .@a$[@menu-2] : .@a$[@menu] );  //Wrong 'cause 2 blocks of statements are running at the same time.
dispbottom ( (@menu == 4) ? .@a$[@menu-4] : ( (@menu == 3)? .@a$[@menu-2] : .@a$[@menu]) );

I'm a bit out-of-dates about the primary ragnarok scripting engine, but many other imperiative languages work like this so I believe it works too.

Edited by Ryokem
Posted (edited)

That is exactly what I meant Annie, thanks. Its a shame I have to create a workaround.

You just have to wonder about which and what to instance to get the scope you want.

EDIT: I just did a typo, I wrote "34" instead of "3".

Edited by Ryokem
Posted (edited)

@Vach

yes, keyworld already explained in that topic

in other programming language

0 && select("1")

it shouldn't execute the select command,

but in rathena script engine it just simply EXECUTE the select("1") for no reason <_< <-- yeah our script engine sux

forced our rathena script to be unoptimized

garet999 must have learned java or other programming language and assume rathena script engine do the same thing, but in truth it wasn't

@Ryokem

your script doesn't work

[Warning]: script:getelementofarray: index out of range (-3)
[Debug]: Data: variable name='.@a$' index=0
[Debug]: Source (NPC): testest at prontera (156,180)

Edited by AnnieRuru
Posted (edited)

@Ryokem

your script doesn't work

[Warning]: script:getelementofarray: index out of range (-3)
[Debug]: Data: variable name='.@a$' index=0
[Debug]: Source (NPC): testest at prontera (156,180)

EDIT: I just did a typo, I wrote "34" instead of "3".

EDIT:

@Annie

I just copy-paste your script, whithout worrying about what it does.

Maybe try something like this to check if really works or not..

set .@s, select("1:2:3:4");
mes "You selected: " + ( (.@s == 1) ? "1" : ( ( .@s == 2 ) ? "2" : ( (.@s == 3 ) ? "3" : "4" ) ) );

Edited by Ryokem

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...