AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read FLOAT from file (https://forums.alliedmods.net/showthread.php?t=223568)

Phant 08-15-2013 05:57

Read FLOAT from file
 
Hello.
I have simple file with FLOAT number, with AMXX plugin I can read this (I use BLOCK_INT, because there is no BLOCK_FLOAT):
PHP Code:

    new file fopen(map_file"r")
    if (
file) {
        new 
Float:r_origin_x
        fread
(filer_origin_xBLOCK_INT)
        
        
set_task(10.0"task_Announce"r_origin_x)
        
        
fclose(file)
    } 

task_Announce:
PHP Code:

public task_Announce(r_origin_x)
{
    
client_print(0print_chat"READED: %f"r_origin_x)


It's okay:
http://firepic.org/images/2013-08/15/bl163l5xftdv.png

But, this code is correct? Because I got two warnings in compilation log:
Code:

// file.sma(46) : warning 2
13: tag mismatch
// file.sma(48) : warning 2
13: tag mismatch

46 string:
PHP Code:

fread(filer_origin_xBLOCK_INT

48 string:
PHP Code:

set_task(10.0"task_Announce"r_origin_x

How I can fix this warnings?

Arkshine 08-15-2013 06:02

Re: Read FLOAT from file
 
Either remove the tag doing _:r_origin_x, or use any:r_origin_x.

Phant 08-15-2013 06:05

Re: Read FLOAT from file
 
Thanks! I just use _:r_origin_x.

ConnorMcLeod 08-15-2013 06:05

Re: Read FLOAT from file
 
2 solutions, in both you need to tag it as Float in the task callback because task index can only be an integer, else you would have to pass it as task parameter.

So :

Either you declare it as integer :
PHP Code:

    new file fopen(map_file"r")
    if (
file) {
        new 
r_origin_x
        fread
(filer_origin_xBLOCK_INT)
        
        
set_task(10.0"task_Announce"r_origin_x)
        
        
fclose(file)
    }  

public 
task_Announce(r_origin_x)
{
    
client_print(0print_chat"READED: %f"Float:r_origin_x)


Either you cast it :

PHP Code:

    new file fopen(map_file"r")
    if (
file) {
        new 
Float:r_origin_x
        fread
(file_:r_origin_xBLOCK_INT)
        
        
set_task(10.0"task_Announce"_:r_origin_x)
        
        
fclose(file)
    }  

public 
task_Announce(r_origin_x)
{
    
client_print(0print_chat"READED: %f"Float:r_origin_x)



Phant 08-15-2013 06:25

Re: Read FLOAT from file
 
I want use second (2) solution, it's works for one FLOAT number, but this is does not work with this code:
PHP Code:

new file fopen(map_file"r")
    if (
file) {        
        new 
Float:r_origin[3]        
        
fread(file_:r_origin[0], BLOCK_INT)
        
fread(file_:r_origin[1], BLOCK_INT)
        
fread(file_:r_origin[2], BLOCK_INT)
        
set_task(10.0"task_Announce"_:r_origin[0], _:r_origin[1], _:r_origin[2])        
        
fclose(file)
    } 

PHP Code:

public task_Announce(r_origin_xr_origin_yr_origin_z)
{
    
client_print(0print_chat"X: %f Y: %f Z: %f"Float:r_origin_xFloat:r_origin_yFloat:r_origin_z)


This code crash my CS :(. What's wrong?

DWIGHTpN 08-15-2013 06:48

Re: Read FLOAT from file
 
PHP Code:

set_task(10.0"task_Announce"_:r_origin[0], _:r_origin[1], _:r_origin[2]) 

->
PHP Code:

 set_task(10.0"task_Announce"0_:r_origincharsmax(_:r_origin)); 

PHP Code:

public task_Announce(r_origin_xr_origin_yr_origin_z

->
PHP Code:

 public task_Announce(r_origin[])
{
     new 
Float:r_origin[0];
     new 
Float:r_origin[1];
     new 
Float:r_origin[2];
     
// code..



Arkshine 08-15-2013 06:53

Re: Read FLOAT from file
 
Because set_task can't pass variables like that. You have to think a bit before doing something randomly.

What is the set_task header ? :

native set_task(Float:time,const function[],id = 0,const parameter[]="",len = 0,const flags[]="" );

id, is supposed to be the Task id.
parameter, is an array where you can pass any data to the callback.

Here, you can do something like : set_task(10.0, "task_Announce", 12654, r_origin, sizeof r_origin );

Callback should look like : public task_Announce( taskid, data[] )

Then you can do Float:data0], Float:data[1] and Float:data[2] to retrieve value.

ConnorMcLeod 08-15-2013 06:57

Re: Read FLOAT from file
 
Just a little correction,

tasks callbacks look like this :

When you don't pass args :
PHP Code:

public FunctionNameTaskIndex 

When you don't pass index :
PHP Code:

public FunctionNameArgs[] ) 

When you pass index and args :
PHP Code:

public FunctionNameArgs[], Index 


Phant 07-10-2014 20:30

Re: Read FLOAT from file
 
My old thread :), again encountered with "tag mismatch" Warning.

This string cause "tag mismatch":
PHP Code:

cs_set_user_team(id2my_func(id)) 

Because I use my_func(id) call for a place simple value (INT).

How to remove warning? I tried:
PHP Code:

cs_set_user_team(id2_:my_func(id)) 

And:
PHP Code:

public _:my_func(id

Did not help.

Backstabnoob 07-10-2014 20:42

Re: Read FLOAT from file
 
First off, that's not a string, it's a function. You're getting tag mismatch because the second parameter is the team, which is tagged with CsTeams. 2 is an untagged integer, so you either have to use CsTeams:2 or the correct value (CS_TEAM_CT?). The third param is also wrong, it's for setting the player's model and it's tagged with CsInternalModel.
Code:

CS_DONTCHANGE
CS_CT_URBAN
CS_T_TERROR
CS_T_LEET
CS_T_ARCTIC
CS_CT_GSG9
CS_CT_GIGN
CS_CT_SAS
CS_T_GUERILLA
CS_CT_VIP

PHP Code:

cs_set_user_team(idCS_TEAM_CTmy_func(id))

// doesn't really need to be public for this
CsInternalModel:my_func(id)
{
    return 
CS_T_TERROR




All times are GMT -4. The time now is 15:57.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.