Author Topic: Passing a object through CrossFunc(..) ?  (Read 652 times)

0 Members and 1 Guest are viewing this topic.

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Passing a object through CrossFunc(..) ?
« on: April 22, 2010, 02:29:12 pm »
Hi.
I were writing a script, wich has an MySQL-account-system in a seperate folder (./scripts/Acc/acc.pas). The main script is located at ./scripts/Zombie/zombie.pas
I'm having trouble with passing some player data as a TUser object between those scripts.

The object is called TUser(defined EXACTLY the same in both scripts), and its definition is:
Code: [Select]
type TUser = record
tagid: string;
cash: integer;
level: integer;
exp, maxexp: integer;
mana, maxmana: integer;
skills: array[1..24] of integer;
end;

In acc.pas is a function: "function LoadUser(tagid: string): TUser;"
In zombie.pas there is declared: "user: array[1..32] of TUser" (player data for each player...)
In a part of a zombie.pas  function is written: "user[id] := CrossFunc([tagid], 'Acc.LoadUser');"

The object doesn't get passed, instead of that I earn an error message. How to pass the user data from Acc to Zombie?
(Please don't tell me this is impossible)

LK

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Passing a object through CrossFunc(..) ?
« Reply #1 on: April 22, 2010, 03:30:03 pm »
as far as I know, you cannot pass any sort of thing as a record, array, or other weird things though due to the fact that the type variant does not support them.
I usually create a pointer-like alternative using an array of <YourType>; but do to the fact you are using more than one script, you will need to create functions like TUser_GetTagId(Ptr: word): string; etc. which are for the basic types, and mayb TUser_GetSkill(Ptr: word; Index: byte): integer; for that.

another extension to that alternative is to have both types be defined on both sides, and create a function that'll use these TUser_* functions to create another object of TUser, and then possible remove the content @ the pointer (unless ur passing more than 1 value of TUser, you really don't even need an array of TUser, just one instance of it). some functions that can hide all the hidden TUser_* and pointer stuff, and in the end just give you TUser is definitely nice.

another idea: cross func something like SetData(all TUser data goes here as various parameters); then in other script u can access it kuz it'll set it's own local TUser object to the stuff set by SetData - might be a problem with the array though

or just do ur crossfunc with all the data in the parameters - again might be a problem with the array though
« Last Edit: April 22, 2010, 03:44:26 pm by DorkeyDear »