Raised This Month: $ Target: $400
 0% 

Read FLOAT from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 08-15-2013 , 05:57   Read FLOAT from file
Reply With Quote #1

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:


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?

Last edited by Phant; 08-15-2013 at 05:58.
Phant is offline
Send a message via ICQ to Phant
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-15-2013 , 06:02   Re: Read FLOAT from file
Reply With Quote #2

Either remove the tag doing _:r_origin_x, or use any:r_origin_x.
__________________

Last edited by Arkshine; 08-15-2013 at 06:02.
Arkshine is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 08-15-2013 , 06:05   Re: Read FLOAT from file
Reply With Quote #3

Thanks! I just use _:r_origin_x.
Phant is offline
Send a message via ICQ to Phant
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-15-2013 , 06:05   Re: Read FLOAT from file
Reply With Quote #4

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)

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 08-15-2013 at 06:06.
ConnorMcLeod is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 08-15-2013 , 06:25   Re: Read FLOAT from file
Reply With Quote #5

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?
Phant is offline
Send a message via ICQ to Phant
DWIGHTpN
Senior Member
Join Date: Jan 2013
Location: Romania.
Old 08-15-2013 , 06:48   Re: Read FLOAT from file
Reply With Quote #6

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


Last edited by DWIGHTpN; 08-15-2013 at 06:49.
DWIGHTpN is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-15-2013 , 06:53   Re: Read FLOAT from file
Reply With Quote #7

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.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-15-2013 , 06:57   Re: Read FLOAT from file
Reply With Quote #8

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 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Old 08-15-2013, 07:11
Phant
This message has been deleted by Phant. Reason: Too late
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 07-10-2014 , 20:30   Re: Read FLOAT from file
Reply With Quote #10

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.

Last edited by Phant; 07-10-2014 at 20:31.
Phant is offline
Send a message via ICQ to Phant
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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