Jump to content
  • 0

Script automatiicaly modifies @menu & other variables


Ajjwidjdneidjenw

Question


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  161
  • Reputation:   31
  • Joined:  12/06/11
  • Last Seen:  

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
Link to comment
Share on other sites

8 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

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.
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  21
  • Topics Per Day:  0.00
  • Content Count:  326
  • Reputation:   19
  • Joined:  09/27/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  161
  • Reputation:   31
  • Joined:  12/06/11
  • Last Seen:  

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

Edit: @Ryokem

Unfortunately I did try that, but it didn't work.

Edited by garet999
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

@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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

@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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  161
  • Reputation:   31
  • Joined:  12/06/11
  • Last Seen:  

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.

I will, no worries :-).

Link to comment
Share on other sites

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.

×
×
  • Create New...