Bug in function parameter when using syntax Struct { "m
Bug in function parameter when using syntax Struct { "m
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?
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?
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
Ah yes... sorry.
If I declare the struct outside the function call, it i ok.
If I use:
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.
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 think this bug is also on pol096.
Thje problem is only when you declare the struct and define function parameter at the same time.
List file
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 });
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
code:
and .lst section:
mm but where finished tmp?
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);
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
This is more complete:
and list file:
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
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: #
And more complete with bugged code:
and list file:
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
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
If I may, at the risk of being wrong,I think the bug is in the order of the parameters being passed.
You have:
and the definition in UO.EM for the CreateNpcFromTemplate is:
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.
You have:
Code: Select all
npc := CreateNpcTemplate(template, loc.x, loc.y, loc.z, who.realm, Struct { "facing" := who.facing } ); Code: Select all
CreateNpcFromTemplate( template, x, y, z, override_properties := 0, realm := _DEFAULT_REALM);[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*
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.
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
http://forums.polserver.com/viewtopic.php?p=8103#8103