Thread: Bool detection
View Single Post
  #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.i = 0;
  for(
temp.var : dynamic) {
    
i = 1;
    if (
makevar(prefix @ var).type() == 3) {
      
lines.add(addSpace("<array='"@ var @"'>", i));
      
i = 2;
      
temp.c = 0;
      for(
temp.var2 : makevar(prefix @ var)) {
        
lines.add(addSpace("<attr["@ c @"]="@ makevar(prefix @ var)[c] @">", i));
        
c ++;
      }
      
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(a, b) {
  
temp.out = a;
  for(
temp.i : b) {
    
temp.ind = a.index(i) > -1;
    if (
ind > -1) out.remove(i);
  }
  return 
out;
}
function 
addSpace(str, int) {
  
temp.i = 0, temp.out = "";;
  while(
i < int*2) {
    
out @= "  ";
    
i += 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