AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error 008: must be a constant expression (https://forums.alliedmods.net/showthread.php?t=60058)

l4ulwtlln 08-26-2007 01:51

error 008: must be a constant expression
 
wats wrong with this? basically i want to have it be dynamic thats why i wont have it as a global

this is just a small portion of the actually thing but it shows basically what i want

/home/groups/amxmodx/tmp3/textyYESGo.sma(14 -- 15) : error 008: must be a constant expression; assumed zero

1 Error.
Could not locate output file /home/groups/amxmodx/public_html/websc3/textyYESGo.amx (compile failed).
PHP Code:

#include <amxmodx>

#define MAX_ALLOWED 64

new const Sound_Test[4][MAX_ALLOWED][64]

new 
SoundNumber

public plugin_precache() {
    
register_plugin("","","")

    
SoundNumber 4

    Sound_Test
[SoundNumber] = {
        
"csound/1.wav"
        
"csound/2.wav"
        
"csound/3.wav"
        
"csound/4.wav"
    
}




Alka 08-26-2007 03:41

Re: error 008: must be a constant expression
 
Oh no. >.> ?!

1.register_plugin(....) should be in plugin_init()
2.3D array :S...why ?!
3.Code should look like this :

Code:

#include <amxmodx>
 
#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"
 
#define SOUNDS_NUMBER 4
 
stock const sound_test[SOUNDS_NUMBER][/*max len*/] = {
 
 "csound/1.wav",
 "csound/2.wav",
 "csound/3.wav",
 "csound/4.wav"
}
 
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR);
}
 
public plugin_precache()
{
 for(new z = 0 ; z < sizeof sound_test ; z++)
 {
  precache_sound(sound_test[z]);
 }
}


l4ulwtlln 08-26-2007 04:00

Re: error 008: must be a constant expression
 
1. dont have to be, it works in plugin_precache if ur only registering the plugin
2. cuz i want it to be dynamic, so when i change SoundNumber to another number, it will be another set of sounds
3. that wouldnt make it dynamic anymore

Drak 08-26-2007 07:48

Re: error 008: must be a constant expression
 
Quote:

Originally Posted by l4ulwtlln (Post 523398)
1. dont have to be, it works in plugin_precache if ur only registering the plugin
2. cuz i want it to be dynamic, so when i change SoundNumber to another number, it will be another set of sounds
3. that wouldnt make it dynamic anymore

You can't do it the way you want to.

Example:
Code:
new SoundNumber = 4; #define MAX_ALLOWED 64 new Sound_Test[SoundNumber][MAX_ALLOWED] = { "csound/1.wav","csound/2.wav","csound/3.wav","csound/4.wav" }

Would NOT work, you would get "Must be a constant expression" error.

This would work:
Code:
new Sound_Test[4][64] = { "csound/1.wav","csound/2.wav","csound/3.wav","csound/4.wav" }

You can't use variables and such, like you where.

Alka 08-26-2007 07:55

Re: error 008: must be a constant expression
 
Also 64 is the len of array!

l4ulwtlln 08-26-2007 13:23

Re: error 008: must be a constant expression
 
so then there is no possible way for this to work?

PHP Code:

#include <amxmodx>
#include <amxmisc>

new SoundsFile[64]
new 
SoundNumber

#define MAX_ALLOWED 64

new const Sound_Test[4][MAX_ALLOWED][64]

new 
Sound_One[MAX_ALLOWED][64]
new 
Sound_Two[MAX_ALLOWED][64]
new 
Sound_Three[MAX_ALLOWED][64]
new 
Sound_Four[MAX_ALLOWED][64]

public 
plugin_precache() {

    
register_plugin("","","")

    new 
cfgDir[32]
    
get_configsdir(cfgDir,31)
    
formatex(SoundsFile63"%s/SoundsFile.ini"cfgDir)

    if(
file_exists(SoundsFile)) {

        
SoundNumber 1

        
new sfLineData[1024]
        new 
file fopen(SoundsFile"rt")

        while(
file && !feof(file)) {
            
fgets(filesfLineData1023)

            
parse(sfLineDataSound_One[SoundNumber], 63Sound_Two[SoundNumber], 63Sound_Three[SoundNumber], 63Sound_Four[SoundNumber], 63)

            
Sound_Test[SoundNumber] = {Sound_One[SoundNumber], Sound_Two[SoundNumber], Sound_Three[SoundNumber], Sound_Four[SoundNumber]}

            
SoundNumber += 1
        
}

        if(
filefclose(file)
    }

    for (new 
1SoundNumber; ++i) {
            
precache_model(Sound_One[i])
            
precache_model(Sound_Two[i])
            
precache_model(Sound_Three[i])
            
precache_model(Sound_Four[i])
    }





All times are GMT -4. The time now is 16:11.

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