AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid function or declaration (https://forums.alliedmods.net/showthread.php?t=21863)

MaximusBrood 12-12-2005 13:15

Invalid function or declaration
 
Why aren't these 2 codings good enough to compile?

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <cstrike> #define TOTALCOLORS 3 new Float:colors[TOTALCOLORS][3] colors[0] = {123.0, 123.0, 123.0} colors[1] = {456.0, 456.0, 456.0} colors[2] = {789.0, 789.0, 789.0} //rest of code

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <cstrike> #define TOTALCOLORS 3 new Float:colors[TOTALCOLORS][3] colors[0][0] = 255.0; colors[0][1] = 0.0; colors[0][2]  = 0.0; colors[1][0] = 165.0; colors[1][1] = 0.0; colors[1][2]  = 0.0; colors[2][0] = 255.0; colors[2][1] = 100.0; colors[2][2]  = 100.0;

In fact, the 2 pieces of code are the same (code 2 is done much more differcult ;) )
(they both don't work)

Whats the problem?

TiA

Brad 12-12-2005 13:17

Are you implying that one of those works and the other gives you the error?

MaximusBrood 12-12-2005 13:23

No, they both give me a compile error :(

(error 010: invalid function or declaration)

Brad 12-12-2005 13:28

Would you be so kind as to provide the entire source?

PM 12-12-2005 13:28

I hope you aren't doing that on the global scope.

MaximusBrood 12-12-2005 13:31

Yes, I was actually doing it on a global scope

Could you expain me whats wrong with that then? :roll:

(@brad ... the whole source doesn't matter, besides, I want to make it a surprise for someone else)

PM 12-12-2005 13:37

Well, in small, you can only have these things on global scope:
  • - comments
    - preprocessor stuff
    - global variable definitions
    - function declarations and definitions

Real statements like assigments are not allowed there (the only entry points in small programs are public functions; the host applications decides when to call those; so from a logical point of view, when would code placed outside any function be executed?) .

If you want to simply initialize the global variable to the specified values, do:
Code:
new Float:colors[TOTALCOLORS][3] = { {123.0, 123.0, 123.0}, {456.0, 456.0, 456.0}, {789.0, 789.0, 789.0} }

Maybe you'd like to declare the variable const as well if small supports it.

edit: freaking typos!

Brad: I'm CHUCK NORRIS and I HAVE A BEARD

Brad 12-12-2005 13:41

Perhaps your problem is that you have code outside of the a function. Either assign the values within your new statement or assign them somewhere else such as plugin_cfg.

Edit: Damn you and your quickness, PM! ;)

MaximusBrood 12-12-2005 13:46

Ah, thnx PM and Brad :D


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

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