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 12-14-2007, 12:54 AM
gemini2 gemini2 is offline
Fincayran Loser
gemini2's Avatar
Join Date: Jun 2007
Location: Georgia
Posts: 174
gemini2 is on a distinguished road
Send a message via AIM to gemini2 Send a message via MSN to gemini2
Bool detection

PHP Code:
function onCreated() {
  
temp.array = {"float""string""object"};
  
temp.object = new TStaticVar();
       
object.array = {"foo""bar"};
       
object.float 3.14;
       
object.integer 7;
       
object.bool true;
       
object.string "baz";
  
  
temp.prefix "temp.object.";
  
  
temp.dynamic object.getDynamicVarNames();
  
temp.vars filter(object.getVarNames(), dynamic);
  
  
temp.lines = {"<objecttype='"object.objecttype() @"'>"};
  
temp.0;
  for(
temp.var : dynamic) {
    
1;
    if (
makevar(prefix @ var).type() == 3) {
      
lines.add(addSpace("<array='"@ var @"'>"i));
      
2;
      
temp.0;
      for(
temp.var2 makevar(prefix @ var)) {
        
lines.add(addSpace("<attr["@"]="makevar(prefix @ var)[c] @">"i));
        
++;
      }
      
lines.add(addSpace("</array>"1));
    }else{
    
temp.suffix = array[makevar(prefix @ var).type()];
    if (
suffix == "float") {
      if (
makevar(prefix @ var) == int(makevar(prefix @ var))) suffix "integer";
    }
    
lines.add(addSpace("<"suffix @"='"@ var @"'>" makevar(prefix @ var) @"</"suffix @">"i));
    }
  }
  
temp.lines.add("</objecttype>");
  for(
temp.line lines) {
    echo(
line);
  }
}
function 
filter(ab) {
  
temp.out a;
  for(
temp.b) {
    
temp.ind a.index(i) > -1;
    if (
ind > -1out.remove(i);
  }
  return 
out;
}
function 
addSpace(strint) {
  
temp.0temp.out "";;
  while(
int*2) {
    
out @= "  ";
    
+= 2;
  }
  
out @= str;
  return 
out;

I have gotten Chompy to teach me alot, so I've been getting better

anyways, the output of the file above:

PHP Code:
<objecttype='TStaticVar'>
  <array=
'array'>
    <
attr[0]=foo>
    <
attr[1]=bar>
  </array>
  <
integer='bool'>1</integer>
  <
float='float'>3.14</float>
  <
integer='integer'>7</integer>
  <
string='string'>baz</string>
</
objecttype
NOW, it says:
NPC Code:

<integer='bool'>1</integer>



Is there a way I can check if it is a bool, because if I check with obj.type() it returns integer
(true = 1, false = 0)

Chompy is away for a week, and this has been on my mind, so I thought I could post it here to get the answer. So.., anyone know?
__________________
Quote:
Originally Posted by Crystia RC
*Angelu: i said the tuba isnt fitting
Oinkness: well use some lube
Quote:
Originally Posted by Angelu View Post
for me the hole is to big and its a way to thin :O
Reply With Quote
  #2  
Old 12-14-2007, 01:35 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
I see you're using Chompy's style as well. lol
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #3  
Old 12-14-2007, 02:40 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
PHP Code:
if ( suffix == "integer" && value in {falsetrue} )
  
suffix "Boolean"
Ideally, just keep it integer. Booleans are integers in Graal, all your doing is adding complexity where it isn't needed.
Reply With Quote
  #4  
Old 12-14-2007, 03:55 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
if (val == true/false) works I believe.
__________________
Stan.
Reply With Quote
  #5  
Old 12-14-2007, 04:22 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
But that doesn't necessarily reflect a true boolean type. As long as var isn't 0/null/"" , it's true. A true boolean type can only be 0 or 1 and Graal doesn't seem to have this type.
Reply With Quote
  #6  
Old 12-14-2007, 05:03 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Chompy is always parsing something.
__________________
Stan.
Reply With Quote
  #7  
Old 12-14-2007, 05:37 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
PHP Code:
public function isbool(val)
return (
val.type() == && val in {truefalse})? true false
Basically, what Novo said.
__________________
Stan.
Reply With Quote
  #8  
Old 12-14-2007, 06:12 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
in true scripting you can replace FALSE with 0 and TRUE with 1. This is a binary principle. Since FALSE is a value of nothing, "0" is used and vice versa. JUst check for a 1 or 0.
__________________
Deep into the Darkness peering...
Reply With Quote
  #9  
Old 12-14-2007, 06:24 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Kyranki View Post
Chompy is always parsing something.
Oh man, that's so true it's almost not funny. But it is funny. Very, very funny.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #10  
Old 12-14-2007, 09:35 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
PHP Code:
public function isBool(val) {
  return (
temp.val in {truefalse});  

should cover it
__________________
Reply With Quote
  #11  
Old 12-14-2007, 09:37 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
I think the best thing to do is to stop pretending that Graal has boolean data types.
Reply With Quote
  #12  
Old 12-14-2007, 02:49 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by coreys View Post
I see you're using Chompy's style as well. lol
Thats actually a pretty common style..
Reply With Quote
  #13  
Old 12-14-2007, 04:39 PM
gemini2 gemini2 is offline
Fincayran Loser
gemini2's Avatar
Join Date: Jun 2007
Location: Georgia
Posts: 174
gemini2 is on a distinguished road
Send a message via AIM to gemini2 Send a message via MSN to gemini2
Well, the problem I thought would arise was when I was going to make it into an object again.. But I guess I'll just do that you guys said, to check if its either 0 or 1..

And about me making a parsing function is basically that Chompy told me that making parsing stuff is good practice :O

But some way to detect if it was a bool or an integer would be nice, for example:
PHP Code:
temp.bool true;
echo(
temp.bool.isBool());
// would echo 1

temp.integer 1;
echo(
temp.integer.isBool());
// would echo 0 

Anyways, thanks guys
__________________
Quote:
Originally Posted by Crystia RC
*Angelu: i said the tuba isnt fitting
Oinkness: well use some lube
Quote:
Originally Posted by Angelu View Post
for me the hole is to big and its a way to thin :O
Reply With Quote
  #14  
Old 12-14-2007, 06:14 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
Float, integer and boolean values are all floating point numbers in Graal script.

This is made for keeping the scripting simple, since you don't need to convert values all the time. You can just do "myvar = 1.5; myvar++;" and the result will be 2.5, while in some languages you can only use "++" on integers. You can check "if (myvar)" instead of doing "if (bool(mybar))", you can do "myvar = true + true + true" to get three.

Basicly the operator automatically converts the variable into the right type if necessary: @ is converting to string, "+" is converting to a number, "&&" is convert to boolean values, "&" is converting to integer (since bit operations only work fine on integer).
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 01:48 AM.


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