Raised This Month: $51 Target: $400
 12% 

Solved What wrong is my array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_COLOURFUL
Member
Join Date: May 2017
Location: Hong Kong
Old 08-08-2017 , 06:45   What wrong is my array?
Reply With Quote #1

PHP Code:
#include <sourcemod>

static String:KVPath[PLATFORM_MAX_PATH];
new 
Words[100][2];

public 
OnPluginStart() 
{
    
CreateDirectory("addons/sourcemod/configs",3);
    
BuildPath(Path_SMKVPathsizeof(KVPath), "configs/speech.cfg");
    
RegConsoleCmd("say"Command_Say);
    
RegConsoleCmd("say_team"Command_Say);
    
LoadWord();
}

public 
LoadWord()
{
    new 
Handle:DB CreateKeyValues("Speech");
    
FileToKeyValues(DBKVPath);
    
KvGotoFirstSubKey(DB); // Start
    
new 1String:iInt[32];
    
IntToString(iiIntsizeof(iInt));
    while(
KvJumpToKey(DBiInt))
    {
        new 
String:match[32], String:answer[32];
        
KvGetString(DB"match"matchsizeof(match));
        
KvGetString(DB"answer"answersizeof(answer));
        
Words[1][0] = match;
        
Words[1][1] = answer;
        
i++
        
IntToString(iiIntsizeof(iInt));
        
CloseHandle(DB);
    }

PHP Code:
"speech"
{
    
"1"
    
{
        
"match"                "I'm gay"
        "answer"            "okay"
    
}
    
"2"
    
{
        
"match"                "I'm handsome"
        "answer"            "okay"
    
}

This is the output :
PHP Code:
// C:\server_backup\tf2\tf\addons\sourcemod\scripting\spse.sp(42) : error 006: must be assigned to an array
// C:\server_backup\tf2\tf\addons\sourcemod\scripting\spse.sp(43) : error 006: must be assigned to an array 
Where is wrong of my code? Plsss help me ;c
__________________
Love Dodgeball

Last edited by _COLOURFUL; 08-08-2017 at 10:32.
_COLOURFUL is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-08-2017 , 06:58   Re: What wrong is my array?
Reply With Quote #2

The code you posted don't even have 42 lines zzzz
8guawong is offline
_COLOURFUL
Member
Join Date: May 2017
Location: Hong Kong
Old 08-08-2017 , 07:13   Re: What wrong is my array?
Reply With Quote #3

i hided some code that i havn't finished yet
__________________
Love Dodgeball
_COLOURFUL is offline
_COLOURFUL
Member
Join Date: May 2017
Location: Hong Kong
Old 08-08-2017 , 07:13   Re: What wrong is my array?
Reply With Quote #4

Quote:
// C:\server_backup\tf2\tf\addons\sourcemod\scri pting\spse.sp(42) : error 006: must be assigned to an array
// C:\server_backup\tf2\tf\addons\sourcemod\scri pting\spse.sp(43) : error 006: must be assigned to an array
Equal to
Quote:
Words[i - 1][0] = match;
Words[i - 1][1] = answer;
__________________
Love Dodgeball

Last edited by _COLOURFUL; 08-08-2017 at 07:14.
_COLOURFUL is offline
inklesspen
Member
Join Date: Nov 2015
Location: Russia, Moscow
Old 08-08-2017 , 08:01   Re: What wrong is my array?
Reply With Quote #5

You want push string... then you need STRING-array
Example:
char sBuffer[64] (on old syntax: new String:sBuffer[64])
and use strcopy instead just setting value
__________________
Mai inglish is veri gud!
inklesspen is offline
Send a message via Skype™ to inklesspen
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-08-2017 , 08:27   Re: What wrong is my array?
Reply With Quote #6

Quote:
Originally Posted by inklesspen View Post
You want push string... then you need STRING-array
To be more clear, your words array should probably be something like new String:words[100][2][32].

Quote:
Originally Posted by inklesspen View Post
and use strcopy instead just setting value
There's nothing wrong with direct assignment given that:
  • The arrays are statically sized (his are)
  • The destination is at least as big as the source (they should be, at least after he fixes his error)
  • You make sure you don't miss a null terminator if you're working with strings (KVGetString ensures it in his case)
Fyren is offline
_COLOURFUL
Member
Join Date: May 2017
Location: Hong Kong
Old 08-08-2017 , 08:52   Re: What wrong is my array?
Reply With Quote #7

This is my latest code, i can't output any result pls help me ;c
PHP Code:
#include <sourcemod>

static String:KVPath[PLATFORM_MAX_PATH];
new 
String:Words[100][4];


public 
Plugin:myinfo 
{
name "Key Values",
author "Hoursplayed.net",
description "",
url "http://hoursplayed.net"
}

public 
OnPluginStart() 
{
    
CreateDirectory("addons/sourcemod/configs",3);
    
BuildPath(Path_SMKVPathsizeof(KVPath), "configs/speech.cfg");
    
RegConsoleCmd("say"Command_Say);
    
RegConsoleCmd("say_team"Command_Say);
    
LoadWord();
}

public 
Action:Command_Say(clientargs)
{
    
decl String:arg1[200];
    
    
GetCmdArg(1arg1sizeof(arg1));
    
    for(new 
0;100;i++)
    {
        if(!
StrEqual(Words[i][0], "") && !StrEqual(Words[i][1], ""))
        {
            if(
StrContains(arg1Words[i][0], false) != -1)
            {
                
PrintToChatAll("%s"Words[i][1]);
                
ServerCommand("sm_slap @all");
            } else continue;
        } else continue;
    }
    return 
Plugin_Continue;
}

public 
LoadWord()
{
    new 
Handle:DB CreateKeyValues("Speech");
    
FileToKeyValues(DBKVPath);
    
KvGotoFirstSubKey(DB); // Start
    
new 1String:iInt[32];
    
IntToString(iiIntsizeof(iInt));
    while(
KvJumpToKey(DBiInt))
    {
        new 
String:match[32], String:answer[32];
        
KvGetString(DB"match"match[1], 32);
        
KvGetString(DB"answer"answer[1], 32);
        
Words[1][0] = match[1];
        
Words[1][1] = answer[1];
        
i++
        
IntToString(iiIntsizeof(iInt));
        
CloseHandle(DB);
    }

PHP Code:
"Speech"
{
    
"0"
    
{
        
"match"        "fml"
        "answer"    "okay"
    
}
    
"1"
    
{
        
"match"        "diu"
        "answer"    "on9"
    
}

__________________
Love Dodgeball

Last edited by _COLOURFUL; 08-08-2017 at 09:26.
_COLOURFUL is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 08-08-2017 , 09:46   Re: What wrong is my array?
Reply With Quote #8

Read again what Fyren said right before your post about the Words array declaration. You need to add a 3rd dimension to hold the actual string info.

Also you start parsing your config file at section "1", so you'd miss your first "0" section.
__________________
Peace-Maker is offline
_COLOURFUL
Member
Join Date: May 2017
Location: Hong Kong
Old 08-08-2017 , 10:31   Re: What wrong is my array?
Reply With Quote #9

Thank everyone for answering me <3
My plugin is working properly now <3
__________________
Love Dodgeball
_COLOURFUL is offline
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 00:51.


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