Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 14,136 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
String trouble #202157
04/13/08 17:39
04/13/08 17:39
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
Hello all!
I read model's name from file, then copy name to structure and morph to that string and get (model_name)

// ERROR
WPN_PM.MDL
: cant open
///////////

typedef struct
{
...
STRING* mdl_name;// Model name
} weapon_stats_struct;

void EquipWeapon(var _weapon)
{
current_weapon = _weapon;
ent_morph(weapon_ent, weapon_box[_weapon].mdl_name);// This!!!
snd_play(weapon_box[_weapon].draw_snd, 30, 0);
}

#define TYPE_TEXT 1
#define TYPE_VAR 2

function load_cfg(var _id, var _type, STRING* _file)
{
var asc_return;
var line = 0;
var start_read = 0;
var line_length = 0;
var longest_line_length = 0;
var delimit_vars = str_to_asc("=");
var delimit_varm = str_to_asc("#");
var delimit_varn = 10;// \n
var errors = 0;

STRING* temp2_str = "#100";
STRING* temp_str = str_create("0");

str_cpy((tooltips_text.pstring)[0], "");

var fhandle = file_open_game(_file);

while (line != _id && errors == 0)
{
if (fhandle == 0) {errors = 1; break;}
if (asc_return == -1) {errors = 2; break;}
asc_return = file_asc_read(fhandle);
if (asc_return == delimit_varn) {line++;}
}

while (start_read != 1 && errors == 0)
{
if (fhandle == 0) {errors = 1; break;}
asc_return = file_asc_read(fhandle);
if (asc_return == delimit_vars) {start_read = 1;}
if (asc_return == delimit_varn) {errors = 3; break;}
if (asc_return == -1) {errors = 2; break;}
}

while (1)
{
if (fhandle == 0 && errors == 0) {errors = 1; break;}
asc_return = file_asc_read(fhandle);

if (asc_return == delimit_varn) {break;}
str_for_asc(temp_str, asc_return);
str_cat((tooltips_text.pstring)[0], temp_str);
if (asc_return == -1){errors = 2; break;}
}

if (errors == 1) {str_cpy((tooltips_text.pstring)[0], "File not found");}
if (errors == 2) {str_cpy((tooltips_text.pstring)[0], "Params not found");}
if (errors == 3) {str_cpy((tooltips_text.pstring)[0], "icon = not found");}
file_close(fhandle);
if (_type == TYPE_VAR) {return str_to_num((tooltips_text.pstring)[0]);}
}

...

And init weapons
..
weapon_box[WEAPON_NULL].mdl_name = load_cfg(1, TYPE_TEXT, "wpn_pm.cfg");

P.S. Sorry for my bad english

Last edited by JackShephard; 04/13/08 17:40.
Re: String trouble [Re: JackShephard] #202161
04/13/08 17:50
04/13/08 17:50
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
Help me please:)

Re: String trouble [Re: JackShephard] #202183
04/13/08 18:57
04/13/08 18:57
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Your english is fine. I haven't gone through the complete code you posted. However at the end there is a pretty obvious error. First you function does not return necessarily anything usefull. Always be carefull when placing return statements inside an if statement. If _type is unequal to TYPE_VAR you haven't defined any return statement at all and the return value will become random data.

Second you're assigning wrong types of data to each other. What you return is a fixed/var type and you're assigning this to a string. Why do you do the conversion to a fixed value with str_to_num? Even the type of your function "function" which means var or fixed is misleading.

So steps to fix this are:
1. replace "function load_cfg(var _id, var _type, STRING* _file)" with "STRING* load_cfg(var _id, var _type, STRING* _file)".
2. Ensure your function returns under any circumstances a pointer to a string.
3. Remove the str_to_num conversion from the return statement.

Btw. That first comment, ist this your error message?


Always learn from history, to be sure you make the same mistakes again...
Re: String trouble [Re: Uhrwerk] #202190
04/13/08 19:35
04/13/08 19:35
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
 Originally Posted By: Uhrwerk

3. Remove the str_to_num conversion from the return statement.


I use str_to_num for conversion str to var, i use .txt for variables
weapon_box[WEAPON_PM].ammo = load_cfg(2, TYPE_VAR, "wpn_pm.cfg");// Good working

Big thanks for you help, would repair!

Re: String trouble [Re: JackShephard] #202194
04/13/08 19:44
04/13/08 19:44
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
Problem is not solved...

STRING* load_cfg(var _id, var _type, STRING* _file)
{
.....
return (tooltips_text.pstring)[0];
}

weapon_box[WEAPON_PM].mdl_name = load_cfg(1, 0, "wpn_pm.cfg");//"wpn_pm.mdl";

 Quote:
That first comment, ist this your error message?

No i see error message...

WPN_PM.MDL
: Can't open file

This is bad =(

Last edited by JackShephard; 04/13/08 19:46.
Re: String trouble [Re: JackShephard] #202196
04/13/08 19:48
04/13/08 19:48
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I am not sure you know what str_to_num does. str_to_num works only if the given string contains a number like in "3.14". If you pass "3.14" to str_to_num it will return 3.14. In any case there is no number in the string str_to_num will return 0. If you took for example str_to_num("filename.mdl") the return value will always be 0. I assume you're trying to pass a filename back. That's why i wrote you should change "function" to "STRING*" and return the string without any conversion.


Always learn from history, to be sure you make the same mistakes again...
Re: String trouble [Re: Uhrwerk] #202203
04/13/08 19:55
04/13/08 19:55
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
I have removed str_to_num and I return only string.
And str_for_num, I use it for convert reading a text in var to use as well as model if I use the text I I do _type = 1, if var that = 0 and it works!
But now I try to read through a name of model from a file and to make morph.

Last edited by JackShephard; 04/13/08 19:55.
Re: String trouble [Re: JackShephard] #202204
04/13/08 19:57
04/13/08 19:57
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Ah, got your point. The error message simply says, that wpn_pm.mdp can't be found. ensure you have copied that file somewhere in your workfolder.


Always learn from history, to be sure you make the same mistakes again...
Re: String trouble [Re: Uhrwerk] #202206
04/13/08 20:00
04/13/08 20:00
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
Yes i copied a file:)

The matter is that if simply to equate
weapon_box[WEAPON_PM].mdl_name = "model.mdl";
All works!
But if to read from a .txt file that it is received that mistake...

Last edited by JackShephard; 04/13/08 20:01.
Re: String trouble [Re: JackShephard] #202208
04/13/08 20:06
04/13/08 20:06
Joined: Sep 2007
Posts: 63
J
JackShephard Offline OP
Junior Member
JackShephard  Offline OP
Junior Member
J

Joined: Sep 2007
Posts: 63
Big thanks for help, tomorrow I shall continue to understand, good night =)

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1