AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   TrieSetArray (https://forums.alliedmods.net/showthread.php?t=295149)

EFFx 03-17-2017 16:04

TrieSetArray
 
I was trying to learn about Tries, but I'm so confused then I decided to post it here.

Thats my code:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

enum eventData
{
    
eChance,
    
eMessage[45]
}

new 
eData[eventData]

new 
Trie:g_tTrie

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_tTrie TrieCreate()
    
    
Load()
    
    
set_task(1.0"hhud", .flags "b")
}

public 
hhud()
{
    new 
Data[eventData]
    
TrieGetArray(g_tTrieeData[eChance], Data[eChance], sizeof Data[eChance])
    
TrieGetString(g_tTrieeData[eMessage], Data[eMessage], sizeof Data[eMessage])
    
    
set_hudmessage(255255255, -1.00.001.01.0)
    
show_hudmessage(0"Chance: %d, Message: %s"Data[eChance], Data[eMessage])
}

public 
plugin_end()
{
    
TrieDestroy(g_tTrie)
}

Load()
{
    new 
File[256]
    
get_configsdir(Filecharsmax(File))

    
add(Filecharsmax(File), "/example.ini")

    new 
iFile fopen(File"r")
    if (!
iFile)
        return

    new 
Data[eventData
    new 
szFile[512], Key[64], Value[256], Type[32], Chance[4], Dummy[4], Message[256]

    while (!
feof(iFile))
    {
        
fgets(iFileszFilecharsmax(szFile))

        
trim(szFile)

        if (
szFile[0] == EOS || szFile[0] == ';' || szFile[0] == '/' && szFile[1] == '/')
            continue

        
strtok(szFileKeycharsmax(Key), Valuecharsmax(Value), '=')
        
        
trim(Key)
        
trim(Value)
        
        if (
equali(Key"ACE"))
        {
            
parse(ValueDummycharsmax(Dummy), Typecharsmax(Type))

            if (
equali(Type"EVENTCHANCE"))
            {
                
parse
                
(
                    
Value
                    
Dummycharsmax(Dummy), 
                    
Typecharsmax(Type), 
                    
Chancecharsmax(Chance),
                    
Dummycharsmax(Dummy)
                )
                
                
Data[eChance] = str_to_num(Chance)
                
TrieSetArray(g_tTrieeData[eChance], Datasizeof Data)
            }

            else if (
equali(Type"MESSAGE"))
            {
                
strtok(ValueTypecharsmax(Type), Messagecharsmax(Message), '@')
                
trim(Message)
                
                
formatex(Data[eMessage], charsmax(Data[eMessage]), "%s"Message)
                
                
TrieSetString(g_tTrieeData[eMessage], Data[eMessage])
            }
        }    
    }



The problem is: The Chance is showing 0, why?

.ini:

Code:

ACE = 1 EVENTCHANCE 2
ACE = 1 MESSAGE @ You just clutched!

I've added a debug:

PHP Code:

Data[eChance] = str_to_num(Chance)
TrieSetArray(g_tTrieeData[eChance], Datasizeof Data)
                
console_print(0"Chance: %s, Data[eChance]: %d, eData[eChance]: %d"ChanceData[eChance], eData[eChance]) 

It shows

Code:

Chance: 2, Data[eChance]: 2, eData[eChance]: 0

Arkshine 03-17-2017 16:11

Re: TrieSetArray
 
eData is never set.

Also, you misunderstand something about Trie. You associate a key (string) to a value (cell, string or array).
I'm not totally sure what you're trying to do with Trie here.

EFFx 03-17-2017 16:23

Re: TrieSetArray
 
I'm just trying to understand more than now. Like how to get a value in string, array, because that tutorial haven't all things - https://forums.alliedmods.net/showthread.php?t=201872

Arkshine 03-17-2017 17:06

Re: TrieSetArray
 
This tutorial has examples on how to retrieve a string or array.

You should explain what you don't understand exactly. If you mean dealing with enum structure which can include array/string, then you need Trie*Array (last example of the link). You should first fix your code to use a real key.

EFFx 03-17-2017 17:48

Re: TrieSetArray
 
I already fixed it by myself. I can post the solution here but its about the my Round End Events, so will not be helpful to others members.


All times are GMT -4. The time now is 18:04.

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