Bug in function parameter when using syntax Struct { "m

Report core bugs regarding the Ultima Online Emulator Core release (version 097). You can attach your Core Dump. One bug per post.
Locked
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Bug in function parameter when using syntax Struct { "m

Post by zandor70 »

Bug in function parameter when using syntax
Struct { "member_name" := member_value }

I have discovered that if I use a function like
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, 0);
the parameter loc.x is passed as integer value, but if I use syntax:
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "facing" := who.facing });
then instead of member x of loc (loc.x) is passed as second parameter the entire struct "loc"....

This is 100% sure a little core bug in parameter function.
The syntax Struct { "member" := value }
should not be used calling functions?
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

that struct is formed incorrectly. Read core-changes.txt on how to correctly build/create a struct.
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

In core changes I have found syntax like:

Code: Select all

      var t := struct { a, b, c };                                  // basic
      var t := struct { a := 4, b := "hey", m := foo(bar(4)) };     // initialized
      var t := struct { a := 4, b := struct { g,h,i }, c };         // with nested structures
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

ok, but do me a favor, try building the struct before the function call, and see if that makes a difference with your two bugs. That gives me something to work with a bit more too (I suck at dealing with the ECompile errors, just so you know in advance, hehe).
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

Ah yes... sorry.
If I declare the struct outside the function call, it i ok.
If I use:

Code: Select all

var tmp := Struct { "facing" := who.facing };
 npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, tmp); 
I have no problem.

I think this bug is also on pol096.
Thje problem is only when you declare the struct and define function parameter at the same time.
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

List file

Post by zandor70 »

Code: Select all

      print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
      npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "facing" := who.facing });
in .lst file:

Code: Select all

print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
166: "trasmitted x="
167: local #4
168: get member id 'x' (0)
169: +
170: " y="
171: +
172: local #4
173: get member id 'y' (1)
174: +
175: " z="
176: +
177: local #4
178: get member id 'z' (2)
179: +
180: Func(1,0): Print
181: #
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "fa
182: local #5
183: local #7
184: local #4
185: local #4
186: get member id 'y' (1)
187: local #4
188: get member id 'z' (2)
189: local #0
190: get member id 'realm' (113)
191: struct
192: local #0
193: get member id 'facing' (9)
194: addmember-assign(facing)
195: 0L
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

mm but
get member id 'x'
where is in .lst file?
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

Exactly. Could you post the same thing, where you create the struct first, and post the lst involving where it sends the function again please? :)

Sorry, at work, but trying to get as much info as possible.
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

code:

Code: Select all

      print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
      var tmp := Struct { "facing" := who.facing };
      npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, tmp);
and .lst section:

Code: Select all

var tmp := Struct { "facing" := who.facing };
182: decl local #0
183: struct
184: local #0
185: get member id 'facing' (9)
186: addmember-assign(facing)
187: :=
188: #
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, tmp);
189: local #7
190: local #4
191: get member id 'x' (0)
192: local #4
193: get member id 'y' (1)
194: local #4
195: get member id 'z' (2)
196: local #0
197: get member id 'realm' (113)
198: local #10
199: 0L
200: makelocal
201: jmp userfunc @274
mm but where finished tmp?
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

I have tryed and in game it take correct facing while I create npc....
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

This is more complete:

Code: Select all

	  loc := TargetCoordinates(who);
    if (loc)
      print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
      var tmp := Struct { "facing" := who.facing };
      npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, tmp);
	    if (npc.errortext)
		    SendSysMessage(who, "NPC " + template + " Creation Failed: " + npc.errortext);
	    endif
    else
      break;
      SendSysMessage(who, "Aborted.");
    endif
and list file:

Code: Select all

loc := TargetCoordinates(who);
161: local #0
162: Func(2,14): TargetCoordinates
163: local4 := 
if (loc)
164: local #4
165: if false goto 221
print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
166: "trasmitted x="
167: local #4
168: get member id 'x' (0)
169: +
170: " y="
171: +
172: local #4
173: get member id 'y' (1)
174: +
175: " z="
176: +
177: local #4
178: get member id 'z' (2)
179: +
180: Func(1,0): Print
181: #
var tmp := Struct { "facing" := who.facing };
182: decl local #0
183: struct
184: local #0
185: get member id 'facing' (9)
186: addmember-assign(facing)
187: :=
188: #
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, tmp);
189: local #7
190: local #4
191: get member id 'x' (0)
192: local #4
193: get member id 'y' (1)
194: local #4
195: get member id 'z' (2)
196: local #0
197: get member id 'realm' (113)
198: local #10
199: 0L
200: makelocal
201: jmp userfunc @274
202: local5 := 
if (npc.errortext)
203: local #5
204: get member 'errortext'
205: if false goto 219
SendSysMessage(who, "NPC " + template + " Creation Failed: " + npc.errortext);
206: local #0
207: "NPC "
208: local #7
209: +
210: " Creation Failed: "
211: +
212: local #5
213: get member 'errortext'
214: +
215: 3L
216: 1000L
217: Func(2,7): SendSysMessage
218: #
219: leave block(1)
220: goto228
break;
221: goto271
SendSysMessage(who, "Aborted.");
222: local #0
223: "Aborted."
224: 3L
225: 1000L
226: Func(2,7): SendSysMessage
227: #

User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

And more complete with bugged code:

Code: Select all

	  loc := TargetCoordinates(who);
      print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
      npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "facing" := who.facing } );
	    if (npc.errortext)
		    SendSysMessage(who, "NPC " + template + " Creation Failed: " + npc.errortext);
	    endif
    else
      break;
      SendSysMessage(who, "Aborted.");
    endif
and list file:

Code: Select all

loc := TargetCoordinates(who);
161: local #0
162: Func(2,14): TargetCoordinates
163: local4 := 
if (loc)
164: local #4
165: if false goto 216
print("trasmitted x="+loc.x+" y="+loc.y+" z="+loc.z); //DEBUG
166: "trasmitted x="
167: local #4
168: get member id 'x' (0)
169: +
170: " y="
171: +
172: local #4
173: get member id 'y' (1)
174: +
175: " z="
176: +
177: local #4
178: get member id 'z' (2)
179: +
180: Func(1,0): Print
181: #
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "fa
182: local #5
183: local #7
184: local #4
185: local #4
186: get member id 'y' (1)
187: local #4
188: get member id 'z' (2)
189: local #0
190: get member id 'realm' (113)
191: struct
192: local #0
193: get member id 'facing' (9)
194: addmember-assign(facing)
195: 0L
196: makelocal
197: jmp userfunc @269
198: set member id 'x' (0) #
if (npc.errortext)
199: local #5
200: get member 'errortext'
201: if false goto 215
SendSysMessage(who, "NPC " + template + " Creation Failed: " + npc.errortext);
202: local #0
203: "NPC "
204: local #7
205: +
206: " Creation Failed: "
207: +
208: local #5
209: get member 'errortext'
210: +
211: 3L
212: 1000L
213: Func(2,7): SendSysMessage
214: #
215: goto223
break;
216: goto266
SendSysMessage(who, "Aborted.");
217: local #0
218: "Aborted."
219: 3L
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

If I may, at the risk of being wrong,I think the bug is in the order of the parameters being passed.
You have:

Code: Select all

npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "facing" := who.facing } ); 
and the definition in UO.EM for the CreateNpcFromTemplate is:

Code: Select all

CreateNpcFromTemplate( template, x, y, z, override_properties := 0, realm := _DEFAULT_REALM);
In your example you have the flags and realm parameters reversed. So make sure in your function CreateNpcTemplate that when you call the internal CreateNpcFromTemplate that you have them in the right order.
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

that's cuz it's a custom function.... notice his is CreateNPCTemplate.... which calls it. Read his code ;)
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

[Edited by Yukiko]

Uhm... Sorry. I guess I am blonde.
That and I don't read things thoroughly.

Just pretend like I never replied in this thread.

*sits quietly off to the side of the room*
Last edited by Yukiko on Sun Apr 22, 2007 6:46 pm, edited 1 time in total.
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

The error is shown in print() when I display parameters first calling function and after called function (inside function body). The function name is not important. THe tests are in post
http://forums.polserver.com/viewtopic.php?p=8103#8103
User avatar
zandor70
Master Poster
Posts: 93
Joined: Fri Feb 10, 2006 10:06 am

Post by zandor70 »

News for this bug in new core 2007-07-15?
Dev team need other info to try to fix?
Locked