Jump to content

  •  

Bug Tracker Migration

June 3rd
Good news everyone! The staff has decided that it is time to slowly kill off this Bug Tracker. We will begin the process of slowly migrating from this Bug Tracker over to our Github Issues which can be found here: https://github.com/HerculesWS/Hercules/issues

Over the next couple of days, I will be closing off any opportunity to create new reports. However, I still will keep the opportunity to reply to existing Bug Reports. Doing this will allow us to slowly fix any bug reports we have listed here so that we can easily migrate over to our Issue Tracker.

Update - June 7th 2015: Creating new bug posts has been disabled. Please use our https://github.com/HerculesWS/Hercules/issues tracker to post bugs. Users are still able to reply to existing bug posts.

- Administration

Issue Information

  • #006804

  • 0 - None Assigned

  • Fixed

Issue Confirmations

  • Yes (1)No (0)
Photo

party member loop issue in script_commands.txt

Posted by Hercules Bot on 19 October 2012 - 09:27 PM

Originally posted by AnnieRuru
http://rathena.org/b..._20#entry147889

   // immediately copy $@partymembercount value to a new variable, since
   // you don't know when 'getpartymember' will get called again for someone 
   // else's party, overwriting your global array.
       set @partymembercount,$@partymembercount;
this is really lol
not only it use temporary player variable
it also creates a rumor that 2 people talking to this npc can clash the $@partymembercount variable

that is totally a rumor
with current script engine
please take a look at what ultramage and mirei said

http://www.eathena.w...ker&showbug=146

The npc will execute on the first player until it arrives in a "waiting for input" or "end" state, like hitting a next; label. Then it'll switch.
Until then, all CPU power is dedicated to executing the script (this is why you shouldn't make long-running scripts, it'll lag players).
This also means no milisecond-like race conditions can happen (but you can still get bad results if you don't plan your next;s properly).


http://www.eathena.w...er&showbug=4935

When there is no *sleep, *sleep2, *next, *close2, *input, *select, *prompt, *menu or any other script command, that pauses the script, between *getpartymember and *copyarray, the operation is atomic and no cross-script exploits can occur, as there is always only one script running at the same time.


so please change it don't have to set another variable anymore, it really cause misunderstanding

Originally posted by MarkZD
premiseIt's a thing that should be carefully looked at the code, not just on incomplete guesses.

The npc will execute on the first player until it arrives in a "waiting for input" or "end" state, like hitting a next;

If it's at the same time, there's no FIRST player, both are the same.


This also means no milisecond-like race conditions can happen

It's not about milisecond race, it's about the same time.


the operation is atomic and no cross-script exploits can occur, as there is always only one script running at the same time.

Atomic operation is fully dependent on the OS, Hardware and the script engine system.
Also, atomic operation is usually meant to adding something, not changing it. (As a text to a file, because it's wrote to different blocks etc).

Technically, there's no atomic operation for a simple var, talking on hardware level, as the hardware has control over what segment will be changed, and it's determined by the cpu operation, so in this case it wouldn't conflict, because the next cicle will always happen after the first.
But, to check this particular case, we need to verify the script engine.

This is why there's lock and semaphore system around a lot of other system.
I already used system which writing to the same variable at same time would deal to broken data.

This is not really a bug, this is more like an improvement to the doc(maybe, if the doc is right, it'll become a bug with this change).
But with this premise, even with this additional assurance it could bug.

And if there's really some lack of lock on var data on the script engine, so, maybe it should be revised, as it can cause bugs.(Of course we may think it doesn't happen as it's very unlikely two request will arrive at the same time, but who knows)?

Just my opnion(But, as I said before, it's something we should look at source code, not just over some guesses).

A good way to check would be creating 2 or more scripts to change same var on a loop and see what happen, possibly will all be okay, but I like to check on everything, however, it won't simulate user clicking on a NPC, as it may have some kind of queue control preventing the descripted bugs, caused by the user side.

Edited by MarkZD, 24 October 2012 - 10:01 AM.


Originally posted by AnnieRuru
yes, this is NOT a bug,
if you click on those 2 bug report link I stated above
both of them are mark as 'Working as Intended'

its the documentation that's provide false fact,
leads members to believe our script engine able to override other script instance
which in this document, its a wrong point

totally nothing wrong with the source code or script commands


anyway, since this one has standing here for some time
I guess I write it in my own sentence

Example:<br /><br />    set .register_num, 5; // set this event need 5 party members to start<br /><br />    // get the charID and accountID of character's party ID<br />        getpartymember getcharid(1), 1;<br />        getpartymember getcharid(1), 2;<br /><br />        if (  $@partymembercount != .register_num ) {<br />            mes "Please form a party of "+ .register_num +" to continue";<br />            close;<br />        }<br /><br />    // loop through both of them using isloggedin command<br />        for ( set .@i, 0; .@i < $@partymembercount; set .@i, .@i +1 )<br />            if ( isloggedin( $@partymemberaid[.@i], $@partymembercid[.@i] ) )<br />                set .@count_online, .@count_online +1 ;<br />    // the reason to extend the search into character ID is because a single<br />    // party can accept multiple characters from the same account. Without<br />    // searching through the character ID, if that player has 2 characters<br />    // from the same account inside that party, it will count twice.<br /><br />        if ( .@count_online != .register_num ) {<br />            mes "All your party members must online to continue";<br />            close;<br />        }<br /><br />    // copy the array to prevent player cheat the system<br />        copyarray .@partymembercid, $@partymembercid, .register_num;<br /><br />        mes "Are you ready ?";<br />        next; // careful here<br />        select "Yes";<br /><br />    // when a script hit a next, menu, sleep or input that pauses the script<br />    // players can take this chance to invite or /leave to make changes in their party<br />    // and to prevent that, we need to call up getpartymember again<br /><br />        getpartymember getcharid(1), 1;<br />        if ( $@partymembercount != .register_num ) {<br />            mes "You've made changes to your party !";<br />            close;<br />        }<br />        for ( set .@i, 0; .@i < $@partymembercount; set .@i, .@i +1 ) {<br />            if ( .@partymembercid[.@i] != $@partymembercid[.@i] ) {<br />                mes "You've made changes to your party !";<br />                close;<br />            }<br />        }<br /><br />    // finally, its safe to start the event<br />        warpparty "event_map", 0,0, getcharid(1);

try to revise this throughly before you commit though
if you have any question, ask ...

Edited by AnnieRuru, 25 October 2012 - 03:40 AM.


Originally posted by KeyWorld
Hey Annie <3

I always say : "Why the hell the script engine generate $@var instead of .@var !?".
It's the same problem with all commands that generate $@var and @var.

I don't think the doc has to be change. It's better to say to novice scripter to copy directly the variable to avoid problems instead of explain them when they should copy the variables to avoid overwrite (more difficult to understand when you are new in script).

Originally posted by MarkZD

Working as Intended'its the documentation that's provide false fact


As we are talking about documentation, if it's a false fact it's an error, so it's a bug, and that's what I'm talking about, the sources you provided don't confirm it's false, they just make guesses about it being, those guesses which I already showed how they could be false.

I'm talking about the quotes you mentioned, I'm just telling it'd only be a trusted "source", if you quoted the source code explaining the algorithm, proving it'd never fail.

You're talking as if it's the perfect true, based on your sources and that's what I'm criticizing.

IMHO.

Edited by MarkZD, 29 October 2012 - 10:22 AM.


Originally posted by Brian
Not sure if I understood everything MarkZD said, but here is a script (with a [wiki='next'] pause) that demonstrates a $@variable being modified externally:

prontera,155,180,0	script	test	910,{<br />	mes "I am storing your char_id.";<br />	set $@the_charid, getcharid(0);<br />	mes "$@the_charid = " + $@the_charid;<br />	mes " ";<br />	<br />	select("Click this NPC with another char, then <Enter>:Don't click the NPC with another char");<br />	<br />	mes "$@the_charid = " + $@the_charid;<br />	close;<br />}



I added AnnieRuru's example in [rev=16840].

Originally posted by AnnieRuru

You're talking as if it's the perfect true, based on your sources and that's what I'm criticizing.IMHO.

Fredzilla was the one who started writing script_commands.txt
and eAAC mod at the time added the documentation he did into eathena SVN 5~6 years ago
without Fredzilla, we would never have a script_commands.txt that explained all the script commands we have

and I mean no offense, script_commands.txt at the time he wrote has many lies
just look at eathena's bug tracker and you'll find out a bunch of them

what I mean is, Fredzilla truely does helped many of us, including me when I tried learning how to script
but even his explanation is not perfect
that's why in this community forum, we should point out each other mistakes and make for a better future


about generating $@var into .@var ....
lol ...
if we do that right now, many scripts will broken lmao
at that time, if you look at my old scripts from year 2007, you'll see that I used
for ( set @i, 0; @i < 10; set @i, @i +1 ) <-- this player variable
because at the time all of us haven't learn this new techniques,
and it was us, especially during year 2008, spreading the new scripting techniques,
and we have found many ways to write a more optimized script now

its the script revolutions that changes this system

and yeah, I also hope from now on, when core developers wants to generate a new array
like battleground $@arenamembers <-- still using global var
I also hope we should reminds them to use .@scope_var to generate the array

but I'm not in the development team though, so I couldn't comment much about this


oh and thx Brian xD
status can be set to fix now


EDIT !!!
wait
2365 if ( $@partymembercount < .register_num ) {
2366 mes "Please form a party of "+ .register_num +" to continue";
2367 close;
2368 }

why is that < operator but not != ....
in my example, I use !=, but you changed to <

Edited by AnnieRuru, 29 October 2012 - 02:03 PM.


Originally posted by Brian
oops I made a typo, thanks Annie.

Fixed in [rev=16841].