AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How is this argument a mismatch? (https://forums.alliedmods.net/showthread.php?t=118216)

wrecked_ 02-08-2010 17:52

How is this argument a mismatch?
 
I'm trying to run a formatex function in a plugin that I'm making, but it gives me some error that tells me
Code:

error 035: argument type mismatch (argument 1)
The line I'm trying to execute is
PHP Code:

formatexmessage63"%s^nHealth: %i^n[%s]"targetnameget_user_healthtarget ), randomsz_Reasons ) ) 

and the message declaration is
Code:
new message[64]
Any help would be appreciated.

Sylwester 02-08-2010 18:08

Re: How is this argument a mismatch?
 
I don't get any errors on this. Paste whole code or at least whole function.

wrecked_ 02-08-2010 18:13

Re: How is this argument a mismatch?
 
PHP Code:

public fw_PlayerPreThinkid )
{
    if( !
is_user_aliveid ) )
    {
        return;
    }
    new 
targetbody
    
    get_user_aiming
idtargetbody )
    
    new 
CsTeams:targteam cs_get_user_teamtarget )
    
    new 
targetname[32]
    
    
get_user_nametargettargetname63 )
    
    new 
message[64]
    
    if( 
targteam == CS_TEAM_T )
    {
        
set_hudmessage000, -1.0, -1.000.00.10.00.0, -)
        
formatexmessage63"%s^nHealth: %i^n[%s]"targetnameget_user_healthtarget ), randomsz_Reasons ) )
    }
    else if( 
targteam == CS_TEAM_CT )
    {
        
set_hudmessage15000, -1.0, -1.000.00.10.00.0, -)
        
formatexmessage63"%s^nHealth: %i^n[Guard]"targetnameget_user_healthtarget ) )
    }
    
show_hudmessageid"%s"message )



Sylwester 02-08-2010 18:20

Re: How is this argument a mismatch?
 
It's because of sz_Reasons. It should be int and you probably declared it as an array. Maybe you want:
PHP Code:

formatexmessage63"%s^nHealth: %i^n[%s]"targetnameget_user_healthtarget ), sz_Reasons[random(MAX_REASONS)] ) 


wrecked_ 02-08-2010 18:30

Re: How is this argument a mismatch?
 
Compiled perfectly. Thanks for the help.

Quick question: I had previously done
PHP Code:

#define MAX_REASONS    7

new const sz_Reasons[MAX_REASONS] = {
    
"Wifebeater",
    
"Robber",
    
"Bank Heister",
    
"Hitman",
    
"Rapist",
    
"Computer Hacker",
    
"Identity Thief"


But it gave me an error saying initialization data exceeds declared size, and I also tried defining it as 8. So I changed it to
PHP Code:

#define MAX_REASONS    7

new const sz_Reasons[MAX_REASONS][] = {
    
"Wifebeater",
    
"Robber",
    
"Bank Heister",
    
"Hitman",
    
"Rapist",
    
"Computer Hacker",
    
"Identity Thief"


Is that correct, the double array? Or should I change it to something different?

Sylwester 02-08-2010 18:41

Re: How is this argument a mismatch?
 
It's correct.

wrecked_ 02-08-2010 18:42

Re: How is this argument a mismatch?
 
Quote:

Originally Posted by Sylwester (Post 1083149)
It's correct.

Aight, thanks for the help.

fysiks 02-08-2010 18:53

Re: How is this argument a mismatch?
 
I would use:

PHP Code:

new const sz_Reasons[][] = {
    
"Wifebeater",
    
"Robber",
    
"Bank Heister",
    
"Hitman",
    
"Rapist",
    
"Computer Hacker",
    
"Identity Thief"
}
// . . .
sz_Reasons[random(sizeof(sz_Reasons))] 

This way when you add or remove "reasons" from the list you won't have to change anything else. The way you currently have it you have to change MAX_REASONS to match the declaration of sz_Reasons.

wrecked_ 02-08-2010 18:56

Re: How is this argument a mismatch?
 
Quote:

Originally Posted by fysiks (Post 1083163)
I would use:

PHP Code:

new const sz_Reasons[][] = {
    
"Wifebeater",
    
"Robber",
    
"Bank Heister",
    
"Hitman",
    
"Rapist",
    
"Computer Hacker",
    
"Identity Thief"
}
// . . .
sz_Reasons[random(sizeof(sz_Reasons))] 

This way when you add or remove "reasons" from the list you won't have to change anything else. The way you currently have it you have to change MAX_REASONS to match the declaration of sz_Reasons.

Good point, especially since the plugin's for 2+ other people.

fysiks 02-08-2010 19:07

Re: How is this argument a mismatch?
 
Yeah, it's not a huge difference but when people (who didn't code it) add or remove things they won't have to worry about needing to change anything else.


All times are GMT -4. The time now is 07:25.

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