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

AMXX Settings API [amxmodx-1.8.3-dev-git4156]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 08-05-2014 , 07:10   AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #1

Hi AM community i have a bug or soemthing to report since AMXX latest build at the moment, i'm using this LOADING / SAVING API https://forums.alliedmods.net/showthread.php?t=243202 and it work's fine with this version of AMXX
Code:
amxmodx-1.8.3-dev-git399
but with latest snapshot "atm" not anymore, no error responded but it's not saving strings to .ini file this one:
Code:
amxmodx-1.8.3-dev-git4156
the folowing function
PHP Code:
amx_save_setting_string_arr 
And so a plugin huge like ZP it's not working anymore with latest snapshot
PHP Code:
public native_save_setting_string_arr(plugin_idnum_params)
{
    
// Retrieve and check params
    
new filename[32], setting_section[64], setting_key[64]
    if (!
RetrieveParams(filenamecharsmax(filename), setting_sectioncharsmax(setting_section), setting_keycharsmax(setting_key)))
        return 
false;
    
    new Array:
array_handle
    
if (!RetrieveArray(array_handle))
        return 
false;
    
    
// Open file for read
    
new path[64], file
    
if (!OpenCustomFileRead(pathcharsmax(path), filenamefiletrue))
        return 
false;
    
    
// Try to find section
    
if (!SectionExists(filesetting_section))
    {
        
// Section not found, append at the end
        
if (!CustomFileAppend(filepath)) return false;
        
WriteSection(filesetting_section)
        
WriteKeyValueArrayString(filesetting_keyarray_handle)
        
fclose(file)
        return 
true;
    }
    
    
// Try to find key in section
    
new keypos_startkeypos_endreplace_values true
    
if (!KeyExists(filesetting_keykeypos_startkeypos_end))
    {
        if (
feof(file))
        {
            
// End of file, append at the end
            
if (!CustomFileAppend(filepath)) return false;
            
WriteKeyValueArrayString(filesetting_keyarray_handle)
            
fclose(file)
            return 
true;
        }
        
        
// End of section, add new key + value pair at the end
        
replace_values false
    
}
    
    
// We have to use a second file (tempfile) to add data at an arbitrary position
    
new temppath[64], tempfile
    
if (!OpenTempFileWrite(temppathcharsmax(temppath), tempfile))
    {
        
fclose(file)
        return 
false;
    }
    
    
// Copy new data into temp file
    
CopyDataBeforeKey(filetempfilekeypos_startkeypos_endreplace_values)
    
WriteKeyValueArrayString(tempfilesetting_keyarray_handle)
    
CopyDataAfterKey(filetempfile)
    
    
// Replace original with new
    
if (!ReplaceFile(filepathtempfiletemppath))
    {
        
fclose(tempfile)
        return 
false;
    }
    
    return 
true;

BUT THE OTHER FUNCTIONS WORK JUST FINE what shall i do ?
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-05-2014 , 10:38   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #2

Tried the example pvoided in the thread, and I get well a file with :

[Admin Models]
V_KNIFE = models/v_knife.mdl

So, it works for me, or so I miss something?
__________________
Arkshine is offline
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 08-06-2014 , 06:09   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #3

Test this plugin it wount work, for multiple files
PHP Code:
// The .ini file in charge
new const SKY_FILE [ ] = { "custom_skys.ini" };

// Using semicolons (;) style
#pragma semicolon 1


// If no sky will be found in .ini file thise will be used as defaults
new const g_skyname [ ] [ ] = 

        
"DrkG""night""xen8"
}; 
if they are more than one , they don't work anymore and nothing is added to the .ini file and when you are connecting to server you will recive multiple error missing, and it's imposible because on lower version of AMXX they work just fine

Thanks
Attached Files
File Type: sma Get Plugin or Get Source (skychanger.sma - 255 views - 3.0 KB)
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-06-2014 , 07:00   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #4

It's because you're using the "reserved" parameter in ArrayCreate().
You create one blank entry, thus you array size is 1. After you check this size if 0, and it fails (btw, no point to check that after creating an array). It does what the documentation says.

Either don't use it, or set to the size of you static arrays and use Set* natives instead.

This might be a side-effect of the changes done in internal code which handles array.
Before it would seem it allocates only memory but you could not still use Set* natives on these entries. This is actually a bug as this doesn't do what doc says.
This new version actually fixes that.
__________________

Last edited by Arkshine; 08-06-2014 at 07:09.
Arkshine is offline
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 08-06-2014 , 11:18   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #5

Thanks even if i understood nothing, please explain to me like a schooler not a proffesor, it was quicker a code example against a post full with advanced informations.

I will downgrade my AMXX version since there is no use to use this latest version, a lot o plugins uses that API and worked fine till now, and what of ZP5.0 Mod shall i rewritte that too ?

Please just tell me what was the latest version of AMXX before you have maded this last update?
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers

Last edited by CryWolf; 08-06-2014 at 11:19.
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-06-2014 , 13:27   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #6

If you are beginner in pawn and tried to copy-paste code without understanding what they do exactly, I can understand you did not understand.

What you have to understand is this:
  • There was a bug with the second parameter (named reserved) of ArrayCreate which did not do what the documentation says -> this has been fixed in new version.
  • Coders should not rely on bugs.
  • MeRcyLeZZ should not use this second parameter in this example (removing the ", 1" from "ArrayCreate(MODEL_MAX_LENGTH, 1)")

An example of usage:

Code:
new Array:handle = ArrayCreate(MAX_LENGTH, 3) ArrayPushString(handle, "something");
If you loop over the array, you will get:
index 0: blank
index 1: blank
index 2: blank
index 3: "something"

> Array size; 4 entries
That's it, the "reserved" parameter created 3 blank entries the first time array is created.
This should be used when you want to pre-fill your array with known datas.
e.g. :
Code:
new const list[][] = {"something", "hello", "world"}; // size of list = 3 entries new Array:handle = ArrayCreate(MAX_LENGTH, sizeof list); for (new i = 0; i < sizeof list; +ii)     ArraySetString(handle, i, list[i])// Not "ArrayPushString" !
You will get:
index 0: "something"
index 1: "hello"
index 2: "world"

> Array size; 3 entries

So,
  • If a plugin doesn't explicit the "reserved" parameter value (e.g. new Array:var = ArrayCreate(MAX_LENGTH) ), then recompiling the plugin with compiler from amxx 1.8.3 will be enough. Most of plugins doesn't care about second param.
  • If a plugin explicits the "reserved" parameter, there are 2 cases: either you removed the "reserved" value or if appropriated (require AMXX 1.8.3 and if you want to prefill) you replace Push by Set. That's the coder's job to not rely on bug and they should update their plugins.


Do you understand better?
__________________

Last edited by Arkshine; 08-06-2014 at 13:29.
Arkshine is offline
Old 08-06-2014, 18:26
CryWolf
This message has been deleted by CryWolf. Reason: Didn't mean it!
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 08-07-2014 , 03:05   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #7

If this is your way to say "thank you for trying to help me" the help will surely stop more sooner than later.
I don't see ANYTHING that looks aggressive, offensive or bad behaviour. He tries to explain how you can solve your problem.
__________________

Mordekay is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2014 , 03:09   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #8

I'm not sure why you are that aggressive toward me, I'm trying to answer you the best I can with my poor english skill. If I have assumed you were beginner, it's because what I've said was not really technical and you did not seem to understand what is the second param. This would make sense to not understand if you were beginner, don't you think? I've assumed that, and tried to answer with examples this time (as you requested). Where did I insult you?!

Quote:
Yes, until now the file was created it was empty but created, but now plugin runs fine no errors no nothing, but file is not created and plugin does nothing!
I've tested your plugin. With the code as it is, removing the second parameter in [ArrayCreate and and it's working as expected (that's why I did explain and answer): file is well created with all entries.

Quote:
Your way of updating AMXX without letting community choose
You may not know, but suggestions are posted on the bug tracker. I'm following that, and sometimes following what people request most often on this forum. So basically, I'm adding what people want. I can't really agree with you.

Quote:
has broken already a lot of plugins
Could you elaborate? What plugins you're talking about? So far, 1.8.3 should be backward compatible. It could have some exception (which we try to avoid as much we can), but here with ArrayCreate this is not a good idea to keep a bug, coder need to learn to not relying on bug.

Quote:
if i came here to ask a question and in return i am accused, no one has borned learned, we must test
You greatly misunderstood me. Why I would 'accuse' you at first place? There no gain to dot hat, I'm helping you...
__________________

Last edited by Arkshine; 08-07-2014 at 14:16.
Arkshine is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2014 , 14:16   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #9

After some thinking and discussing with someone, I was concerned by breaking plugin which is never welcomed, even if this was a bug. Will try to figure out a way, either by ignoring this param or put back the same behavior if we can.

EDIT: Fixed in latest build. Old behavior is back, and this means that if coder want to prefill with real blank entries like documentation was saying, you should use instead ArrayResize which does basically the same thing.
__________________

Last edited by Arkshine; 08-07-2014 at 17:43.
Arkshine is offline
Old 08-07-2014, 17:48
CryWolf
This message has been deleted by CryWolf.
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-07-2014 , 18:05   Re: AMXX Settings API [amxmodx-1.8.3-dev-git4156]
Reply With Quote #10

Quote:
accusing me with author steal, by agressing me
This is starting to be unpleasant. Could you stop to say that when it's obviously false, please? I did not say nothing about "stealing" or something, nor being aggressive. What's wrong with you? After all the time I've passed to check/help you, even when you were aggressive for no reason, saying that make me feel I've just lost my time.
__________________

Last edited by Arkshine; 08-07-2014 at 18:06.
Arkshine 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 18:22.


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