PenUltima Online Forum Index Official Core: 096.7
Official Core: 097 2008-02-26
Donate towards the POL web hosting bill!
 POL Home   FAQ   Search    Memberlist   Usergroups    Register    Profile   Log in to check your private messages   Log in
Bug in function parameter when using syntax Struct { "m
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PenUltima Online Forum Index -> Bug Reports 097
Display posts from previous:   

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 6:39 am    Post subject: Bug in function parameter when using syntax Struct { "m Reply with quote

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?

Author Message
MuadDib
POL Developer


Joined: 13 Feb 2006
Posts: 830
Location: Indiana, USA

PostPosted: Sat Apr 21, 2007 8:16 am    Post subject: Reply with quote

that struct is formed incorrectly. Read core-changes.txt on how to correctly build/create a struct.

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 9:58 am    Post subject: Reply with quote

In core changes I have found syntax like:

Code:

      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

Author Message
MuadDib
POL Developer


Joined: 13 Feb 2006
Posts: 830
Location: Indiana, USA

PostPosted: Sat Apr 21, 2007 10:14 am    Post subject: Reply with quote

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).

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:18 am    Post subject: Reply with quote

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

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.

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:31 am    Post subject: List file Reply with quote

Code:

      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:

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

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:32 am    Post subject: Reply with quote

mm but
get member id 'x'
where is in .lst file?

Author Message
MuadDib
POL Developer


Joined: 13 Feb 2006
Posts: 830
Location: Indiana, USA

PostPosted: Sat Apr 21, 2007 10:35 am    Post subject: Reply with quote

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? Smile

Sorry, at work, but trying to get as much info as possible.

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:45 am    Post subject: Reply with quote

code:
Code:

      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:

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?

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:47 am    Post subject: Reply with quote

I have tryed and in game it take correct facing while I create npc....

Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:51 am    Post subject: Reply with quote

This is more complete:
Code:

     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:

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: #


Author Message
zandor70



Joined: 10 Feb 2006
Posts: 79
Location: Italy

PostPosted: Sat Apr 21, 2007 10:55 am    Post subject: Reply with quote

And more complete with bugged code:
Code:

     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:

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

Author Message
Yukiko



Joined: 02 Feb 2006
Posts: 1094
Location: Southern Central USA

PostPosted: Sat Apr 21, 2007 10:55 pm    Post subject: Reply with quote

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:
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:
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.

Author Message
MuadDib
POL Developer


Joined: 13 Feb 2006
Posts: 830
Location: Indiana, USA

PostPosted: Sun Apr 22, 2007 12:47 am    Post subject: Reply with quote

that's cuz it's a custom function.... notice his is CreateNPCTemplate.... which calls it. Read his code Wink

Author Message
Yukiko



Joined: 02 Feb 2006
Posts: 1094
Location: Southern Central USA

PostPosted: Sun Apr 22, 2007 2:40 am    Post subject: Reply with quote

[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 10:46 pm; edited 1 time in total

Post new topic   Reply to topic    PenUltima Online Forum Index -> Bug Reports 097 All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 




Powered by phpBB © 2001, 2005 phpBB Group :: Theme & Graphics by GHS & Scott E. Royalty