Possible eScript scope related bug

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

Possible eScript scope related bug

Post by phao »

I was working on this code, and after getting this first version complete, I went to compile it, for the first time.

Here is the code: http://pastie.org/pastes/1466209/text

Note that there is a function called sfx. But other functions also have sfx as the name of an argument.

Code: Select all

function shot_sfx(attacker, defender, hit, sfx, miss_sfx)
function hit_or_miss(mob, hit, sfx, miss_sfx)
In the body of those functions ecompile doesn't seem to be recognizing sfx as the argument, but as the global function.

I'm getting this error message:
Compiling: ./scripts/combat_fx.src
Expected '(' after function name 'sfx'
Error getting arguments for function PlaySoundEffect
File: /opt/pol099/pkg/combat/scripts/combat_fx.src, Line 46

Error compiling statement at /opt/pol099/pkg/combat/scripts/combat_fx.src, Line 46
Error in function 'shot_sfx', File: /opt/pol099/pkg/combat/scripts/combat_fx.src, Line 46

Error in function 'shot_sfx'.
File: /opt/pol099/pkg/combat/scripts/combat_fx.src, Line 46
I'm not sure what are the scope rules of eScript, and if this is just a "misguided" error messages, as many ecompile throws, but if ecompile isn't making a mistake, and the scope of eScript is anything like C's scope, there's a bug there. The fact that sfx is the name of an argument of those functions should shadow the global function sfx.

If I change the name of the function sfx to do_sfx(), the error disappear and ecompile compiles the code with no complaints.

Could someone tell me if this is a bug or not? It looks very much like so, but I may be doing something wrong; or I was right about the bevahior (i.e. ecompile wasn't compiling because of name conflicts), but the behavior (paramenter name not shadowing external name) is intentional (maybe the language was designed that way, which I kinda doubt).

I'm running POL 099 on Linux.
Polytropon
New User
Posts: 19
Joined: Wed Sep 15, 2010 9:47 pm

Re: Possible eScript scope related bug

Post by Polytropon »

but the compiler is showing the error! : Expected '(' after function name 'sfx'


you should write:

function shot_sfx(attacker, defender, hit, sfx(), miss_sfx)
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

Re: Possible eScript scope related bug

Post by phao »

Line 46, which is the line of the error, is the first line of that function you mentioned (it's one line below the line you talked about). It's this line:

Code: Select all

  PlaySoundEffect(attacker, sfx);
ecompile tells "expected ( after sfx" because it's thinking sfx is the global function and not the parameter, which is a variable. If that is true or not is what I wanna know. I believe it is, and if I'm right, that's probably a bug.

And, afaik, something like you did is illegal, but since eScript is not fully, or well, documented, I won't bet on that.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: Possible eScript scope related bug

Post by *Edwards »

When you first call a function in your script, you must also include the arguments:

Code: Select all

program Example( who )
        Playmusic( who );
endprogram

function Playmusic( who )
        PlaySoundEffect( who, 0x19 );
endfunction
When you call the core function

Code: Select all

PlaySoundEffect( who, sfx )
the ecompile thinks sfx is a variable. You must give it a value. You can find these values with UOFiddler or you can get some from "include/client.inc". With this function you can only parse integer or hex. All infos found in the docs section of POL site.

for exemple:

Code: Select all

var the_sfx := 0x19;
program Example( who )
        Playmusic( who );
endprogram

function Playmusic( who )
        PlaySoundEffect( who, the_sfx );
endfunction
In your code you just do not give value to PlaySoundEffect. By default the compiler thinks it's a variable but "sfx" has never been initialized in your script. Give it a value or parse the info directly in the function.

Escript is also very well documented. You just must take the time to search at the good place.

http://docs.polserver.com/pol099/guides ... criptguide
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

Re: Possible eScript scope related bug

Post by phao »

*Edwards wrote:When you first call a function in your script, you must also include the arguments:

Code: Select all

program Example( who )
        Playmusic( who );
endprogram

function Playmusic( who )
        PlaySoundEffect( who, 0x19 );
endfunction
When you call the core function

Code: Select all

PlaySoundEffect( who, sfx )
the ecompile thinks sfx is a variable. You must give it a value. You can find these values with UOFiddler or you can get some from "include/client.inc". With this function you can only parse integer or hex. All infos found in the docs section of POL site.

for exemple:

Code: Select all

var the_sfx := 0x19;
program Example( who )
        Playmusic( who );
endprogram

function Playmusic( who )
        PlaySoundEffect( who, the_sfx );
endfunction
In your code you just do not give value to PlaySoundEffect. By default the compiler thinks it's a variable but "sfx" has never been initialized in your script. Give it a value or parse the info directly in the function.

Escript is also very well documented. You just must take the time to search at the good place.

http://docs.polserver.com/pol099/guides ... criptguide
I'm not sure I understand you.

But sfx, the parameter, is given a value when hit_or_miss (or the other function) is called. It's being given a value. The problem is that ecompile is confusing the names. If I change the names everything goes fine, as I mentioned.
Polytropon
New User
Posts: 19
Joined: Wed Sep 15, 2010 9:47 pm

Re: Possible eScript scope related bug

Post by Polytropon »

You must write the brackets next to "sfx" to be considered a function, even if that function need no arguments. If you don´t, it will think it´s a variable.

as I said before, change:

function shot_sfx(attacker, defender, hit, sfx, miss_sfx)

to

function shot_sfx(attacker, defender, hit, sfx(), miss_sfx)
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

Re: Possible eScript scope related bug

Post by phao »

Polytropon wrote:You must write the brackets next to "sfx" to be considered a function, even if that function need no arguments. If you don´t, it will think it´s a variable.

as I said before, change:

function shot_sfx(attacker, defender, hit, sfx, miss_sfx)

to

function shot_sfx(attacker, defender, hit, sfx(), miss_sfx)
I like that you're trying to help, but please read the problem description.

Btw, I already talked to turley, and he told me that this is a bug, and that they're are already aware of it.
Post Reply