Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   enum and makevar (https://forums.graalonline.com/forums/showthread.php?t=73041)

Chompy 03-24-2007 04:15 PM

enum and makevar
 
Do makevar() even work with enum?

PHP Code:

enum test
{
  
foo "bar",
  
bar "foo"
}
function 
onCreated()
{
  
temp."foo";
  echo( 
"TEST:" SPC makevar"test." temp.a));

  echo( 
"TEST:" SPC test.foo);


This echoes:

HTML Code:

TEST:
TEST: bar

Do makevar work with enum?

Skyld 03-24-2007 04:19 PM

enums are for mainly integers, not strings. I think you want to use consts for strings, i.e.
PHP Code:

const foo "bar"


Chompy 03-24-2007 04:25 PM

Quote:

Originally Posted by Skyld (Post 1292570)
enums are for integers, not strings. I think you want to use consts for strings, i.e.
PHP Code:

const foo "bar"



PHP Code:

const foo "bar";

function 
onCreated()
{
  
temp."foo";
  echo( 
"TEST:" SPC makevartemp.a));

  echo( 
"TEST:" SPC foo);


Produces
HTML Code:

TEST:
TEST: bar

Still not working :[


Edit:
this is what I originally tested/needed it for:

PHP Code:

//#CLIENTSIDE
enum category
{
  
Weapons,
  
Accorories,
  
Armor,
  
Potions,
  
Quest,
  
Food,
  
Misc
}
function 
onCreated()
{
  
this.category "Food";
  
this.category_index makevar"category." this.category);
  echo( 
this.category ":" SPC this.category_index);


Produces
HTML Code:

Food: 0

Becuase I need the index of the current category for something I am working on..

Skyld 03-24-2007 04:26 PM

I guess it doesn't work, then. consts and enums probably aren't in the same variable scope, or are preprocessed during bytecode compilation, I'm not sure.

Chompy 03-24-2007 04:29 PM

Quote:

Originally Posted by Skyld (Post 1292573)
I guess it doesn't work, then. consts and enums probably aren't in the same variable scope, or are preprocessed during bytecode compilation, I'm not sure.

Would be nice if it could be added, or I gotta do alot of uneccasary coding just to get the correct index of the category (read edited post)

Skyld 03-24-2007 04:40 PM

Quote:

Originally Posted by Chompy (Post 1292574)
Would be nice if it could be added, or I gotta do alot of uneccasary coding just to get the correct index of the category (read edited post)

Hmm, makevar() is quite untidy. :| Does (@ "foo") or so do anything in place of makevar()?

Chompy 03-24-2007 04:43 PM

Quote:

Originally Posted by Skyld (Post 1292576)
Hmm, makevar() is quite untidy. :| Does (@ "foo") or so do anything in place of makevar()?

Still nothing :[

PHP Code:

enum test
{
  
foo "bar",
  
bar "foo"
}
function 
onCreated()
{
  
temp."foo";
  echo( 
"TEST:" SPC test.( @ temp.a));
  echo( 
"TEST:" SPC test.( @ "foo"));
  echo( 
"TEST:" SPC test.foo);


Produces
HTML Code:

TEST:
TEST:
TEST: bar

same with this..
PHP Code:

enum category
{
  
Weapons,
  
Accorories,
  
Armor,
  
Potions,
  
Quest,
  
Food,
  
Misc
}
function 
onCreated()
{
  
this.category "Food";
  
this.category_index category.(@ this.category);
  echo( 
this.category ":" SPC this.category_index);


produces
HTML Code:

Food: 0

Inverness 03-24-2007 05:25 PM

Couldn't one use TStaticVar in place of an enum?
It would work about the same and be accessible from other objects.
It might require you to type a little bit more but its more useful in the end, yes?

Admins 03-24-2007 06:43 PM

Consts and enums are const values which are replacing script variables at compile-time, that's why you cannot use consts/enums from other scripts either. The are basicly what "defines" are in C/C++/Pascal etc.
If you want a dynamic variable then create a dynamic variable (this.foo etc.)

Inverness 03-25-2007 06:13 PM

But in the end its unlikely the values will be modified anyhow, unless some other person with NC changes them, but them thats easy to avoid. So I can't see a reason to use constants or enums considering their inability to be used outside of the current object, thats why I would use a static var.

Just my two cents.


All times are GMT +2. The time now is 03:52 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.