AlliedModders

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

Marcin RN 12-17-2014 08:22

Stack implementation
 
Hi!
Is there any stack implementation available in amxmodx?
I only found this:
https://www.amxmodx.org/api/cellstack/__raw

But this seems to be not available in latest amxmodx.
Any thoughts?

Best regards,
Marcin

Arkshine 12-17-2014 08:59

Re: Stack implementation
 
It's available in 1.8.3 dev build.

http://www.amxmodx.org/snapshots.php

Marcin RN 12-17-2014 09:07

Re: Stack implementation
 
Okay, I just found that it's in dev version :oops:

However, I have an issue with it.

I need an array that holds stack handles for each of player
Code:

new Stack:g_LastHP[33]

for ( new i = 1; i <= g_MaxPL; i++ )
        g_LastHP[i] = CreateStack()

However, if I try to use any cellstack function on any handle it would print Invalid handle error.

Code:

PushStackCell(g_LastHP[id], pev(target, pev_health))

L 12/17/2014 - 15:02:13: Invalid array handle provided (0)
L 12/17/2014 - 15:02:13: [AMXX] Displaying debug trace (plugin "test.amxx", version "2.8.2")
L 12/17/2014 - 15:02:13: [AMXX] Run time error 10: native error (native "PushStackCell")

For a single stack handle (not an array) it works fine:

Code:

        g_testStack = CreateStack()
               
        PushStackCell(g_testStack, 5)
        PushStackCell(g_testStack, 25)
        new z;
        PopStackCell(g_testStack, z)
        server_print("%d", z)  //prints 25

Any help appreciated!

Arkshine 12-17-2014 09:52

Re: Stack implementation
 
Did you try to debug at least? Like printing each cell of g_LastHP ?

Error states you pass an invalid handle, meaning g_LastHP[i] returns 0. Are you sure that "i" is not 0, because at 0 you don't create handle.

Marcin RN 12-17-2014 10:04

Re: Stack implementation
 
Quote:

Originally Posted by Arkshine (Post 2236410)
Did you try to debug at least? Like printing each cell of g_LastHP ?

Error states you pass an invalid handle, meaning g_LastHP[i] returns 0. Are you sure that "i" is not 0, because at 0 you don't create handle.

Oops that's embarassing :oops::oops:

Turns out that g_MaxPL was 0 from the start. Everything is fine now.

Sorry for bothering you and thanks for the help!

HamletEagle 12-17-2014 11:39

Re: Stack implementation
 
Quote:

Originally Posted by Arkshine (Post 2236410)
Did you try to debug at least? Like printing each cell of g_LastHP ?

Error states you pass an invalid handle, meaning g_LastHP[i] returns 0. Are you sure that "i" is not 0, because at 0 you don't create handle.

How a stack is different from an array ? Or better to ask what is a stack. I really have no ideea :shock:

Arkshine 12-17-2014 12:39

Re: Stack implementation
 
Stack is just another dynamic array like.

Difference is how you store and retrieve elements, that's it in a stack way.

http://www.wikiwand.com/en/Stack_(abstract_data_type)

You can check also the test plugin in scripting/testsuite/.


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

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