How to create a constant string -
rt-2 - 26.01.2017
How to create a constant string?
I am trying
Код:
new const INV_OBJ_menuTitle[] = "Inventory";
new dialog_title[64] = INV_OBJ_menuTitle;
and I get the error: error 008: must be a constant expression; assumed zero (on the second line)
but when I try
Код:
const INV_OBJ_menuTitle[] = "Inventory";
new dialog_title[64] = INV_OBJ_menuTitle;
I get the error: error 001: expected token: "=", but found "[" (on the first line)
How am I supposed to set a constant string, is it possible?
Thank you
Re: How to create a constant string -
Dayrion - 26.01.2017
PHP код:
static const INV_OBJ_menuTitle[] = "Inventory";
Re: How to create a constant string -
rt-2 - 26.01.2017
Quote:
Originally Posted by Dayrion
PHP код:
static const INV_OBJ_menuTitle[] = "Inventory";
|
Thank you,
But in the documentation, it says that the variable with a static scope would only be available for the script in the same "section" it was created, does anyone knows what that means a "section" refers to?
https://sampwiki.blast.hk/wiki/Keywords:Initialisers#static
Thank you,
rt-2
Re: How to create a constant string -
Eoussama - 26.01.2017
It means a block of code, the code between the two "{}", which defines an independent scope
see here
https://sampwiki.blast.hk/wiki/Scripting_Basics#Scope
Re: How to create a constant string -
Dayrion - 26.01.2017
Quote:
Originally Posted by blinkpnk
|
If you declare ur variable as a global variable, you can use it in your whole script. If you include your script in an another one, you cannot use this variable.
Re: How to create a constant string -
rt-2 - 26.01.2017
Quote:
Originally Posted by Dayrion
PHP код:
static const INV_OBJ_menuTitle[] = "Inventory";
|
Код:
static const INV_OBJ_menuTitle[] = "Inventory";
function(attr1)
{
new dialog_title[64] = INV_OBJ_menuTitle;
}
This is not working, I am still getting "error 008: must be a constant expression; assumed zero" (on fourth line)
Note that I am setting up the variable at the top of my script and trying to use the constant value in a function/callback.
Thank you
Re: How to create a constant string -
Vince - 26.01.2017
Quote:
Originally Posted by Eoussama
|
No. That's something else entirely. A section basically refers to the file itself, e.g. a global static variable in an include file will only be visible to that file. There is also a directive #section that can be used to declare multiple sections within a file, but that doesn't work. Perhaps it is fixed in Zeex' compiler.
Re: How to create a constant string -
Dayrion - 26.01.2017
Quote:
Originally Posted by blinkpnk
Код:
static const INV_OBJ_menuTitle[] = "Inventory";
function(attr1)
{
new dialog_title[64] = INV_OBJ_menuTitle;
}
This is not working, I am still getting "error 008: must be a constant expression; assumed zero" (on fourth line)
Note that I am setting up the variable at the top of my script and trying to use the constant value in a function/callback.
Thank you
|
PHP код:
static const INV_OBJ_menuTitle[][] = {"Inventory"};
function(attr1)
{
new dialog_title[64] = INV_OBJ_menuTitle;
}
Re: How to create a constant string -
rt-2 - 26.01.2017
Quote:
Originally Posted by Dayrion
PHP код:
static const INV_OBJ_menuTitle[][] = {"Inventory"};
function(attr1)
{
new dialog_title[64] = INV_OBJ_menuTitle;
}
|
Can you test before posting?
It gives the same error.
Re: How to create a constant string -
Dayrion - 26.01.2017
Quote:
Originally Posted by blinkpnk
Can you test before posting?
It gives the same error.
|
Of course a constant can contain a string. Stop being rude when I'm trying to help you. -.-
PHP код:
#define title "Invetory"
function(attr1)
{
new dialog_title[64] = title;
}
working fine with basic warnings.