How to create a constant string
#1

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
Reply
#2

PHP код:
static const INV_OBJ_menuTitle[] = "Inventory"
Reply
#3

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
Reply
#4

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
Reply
#5

Quote:
Originally Posted by blinkpnk
Посмотреть сообщение
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
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.
Reply
#6

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
Reply
#7

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
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
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.
Reply
#8

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;

Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)