Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-24-2007, 04:15 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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?
__________________
Reply With Quote
  #2  
Old 03-24-2007, 04:19 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
enums are for mainly integers, not strings. I think you want to use consts for strings, i.e.
PHP Code:
const foo "bar"
__________________
Skyld

Last edited by Skyld; 03-24-2007 at 04:29 PM..
Reply With Quote
  #3  
Old 03-24-2007, 04:25 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Skyld View Post
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..
__________________
Reply With Quote
  #4  
Old 03-24-2007, 04:26 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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.
__________________
Skyld
Reply With Quote
  #5  
Old 03-24-2007, 04:29 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Skyld View Post
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)
__________________
Reply With Quote
  #6  
Old 03-24-2007, 04:40 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Chompy View Post
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()?
__________________
Skyld
Reply With Quote
  #7  
Old 03-24-2007, 04:43 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Skyld View Post
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
__________________
Reply With Quote
  #8  
Old 03-24-2007, 05:25 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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?
__________________
Reply With Quote
  #9  
Old 03-24-2007, 06:43 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.)

Last edited by Admins; 03-25-2007 at 11:38 PM..
Reply With Quote
  #10  
Old 03-25-2007, 06:13 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:36 PM.


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