no possibility to save a handle in a string

Posted By: Sinthoras

no possibility to save a handle in a string - 08/20/07 18:53

Hiho,

there might be a problem with saving the handle number of a panel into a string:

Code:

panel* PanelPointer;
panel TestPanel { ... }
...
temp = handle(TestPanel);
str_for_num(str1, temp); //save the handle to the string
PanelPointer = ptr_for_handle(temp); //works
temp = str_to_num(str1); //get the handle out of the string

PanelPointer = ptr_for_handle(temp); //does not work (returns zero)
...



The Problem occurs both on predefined panels and on panels created by pan_create, but it does NOT occur on string pointers/handles.

[EDIT] V6.60, C-Script [/EDIT]
Posted By: jcl

Re: no possibility to save a handle in a string - 08/21/07 05:33

Of course this won't work. A handle can be stored in a variable, but is no variable and can not be converted to a number string.
Posted By: Sinthoras

Re: no possibility to save a handle in a string - 08/21/07 11:09

Well, acording to the manual, it IS a number..

Manual "handle":
Code:

A handle is similar to a pointer, but is just a number and therefore can be assigned to any variable or skill.



And if it was no number... why does the string conversion work for string pointers/handles then?
Posted By: quasarchangel

Re: no possibility to save a handle in a string - 08/21/07 15:11

Why do you want to save it to a string?
Posted By: Uhrwerk

Re: no possibility to save a handle in a string - 08/21/07 18:01

Well, i guess the problem is the conversion to the string and back, where you might loose precision. Keep in mind, that a handle is not equivalent to a var. A handle is an int, that contains a bit mask for the handle type and a unique number.
Posted By: Sinthoras

Re: no possibility to save a handle in a string - 08/22/07 09:48

@quasarchangel

I want to save it to a string because my current database system works only with strings. This results from the pseudo database language I wrote for it. If theres no other way but keeping the handle a var, I have to change the language a bit.

@Uhrwerk

The precision could be the problem, yes. I will try to shift the commands to a dll, maybe it is possible to convert it by C++.


The strange thing about it is still that the conversion is possible for string handles.

[EDIT]
In a dll, it works with the itoa/atoi functions (also with "var"), but not with the str_for_num/str_to_num ones.
Might be the precision problem.

Code:

char c[20];
_itoa_s(handle(pointer), c, 20, 10);
str_cpy(str1, c);

and

return(ptr_for_handle(atoi(_CHR(str1))));



Problem solved.
[/EDIT]
Posted By: testDummy

Re: no possibility to save a handle in a string - 08/22/07 10:44

Saving handles as strings (not 3DGS strings), and reading them back in or resurrecting them again (via C / C++ file IO), in compliment with the 3DGS load / save instructions (in C-Script), seems to work as expected using a C++ interface and the 3DGS plugin SDK. This seemed to work well enough when I implemented load / save functionality for my entity lists eLL plugin (C file IO) and later for the newer version, el (C++ file stream classes IO) plugin.
© 2024 lite-C Forums