Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   {} vs || (https://forums.graalonline.com/forums/showthread.php?t=74499)

Angel_Light 06-10-2007 03:17 AM

{} vs ||
 
I've came across two different ways to do a few things for instance I can do

PHP Code:

 extent = { 3232}; 

or
PHP Code:

 extent "32 32"

aswell as

PHP Code:

 if (this.x in |032|) { 

or
PHP Code:

 if (this.x in {032}) { 

both methods do the same thing so my question is why are 2+ different ways to do the same thing? Wouldn't it be simpler to just have one way so people don't get confused and such, or is there some other reason that I can not see because of my ignorance? Just curious thats all.

Twinny 06-10-2007 03:28 AM

I think extent = {300,250}; and extent = "300 250"; was just to allow compatibility between both torque and GS2. Or maybe GS2 and GS1... Not sure which case but I do believe it's for compatibility.

I use extent = {300,250}; but I'm not sure if this is the best way.

As for checks,
PHP Code:

function onCreated()
{
  
this.test 10
  if (
this.test in |5,50|)
  {
    echo(
"Test 1 true");
  }
  if (
this.test in {5,50})
  {
    echo(
"Test 2 true");
  }


Test 1 is true while test 2 isn't. Basically, | | tests for all numbers in between. So for |5,50| it checks if the number is in between 5 and 50. Using {5,50} however only checks if the number is part of the array: it doesn't check in between numbers. So unless the result is 5 or 50, it's false.

Array checking does have one advantage though, it can check for multiple values while not needing to check all in between values. For example, if I did
PHP Code:

function onCreated()
{
  
this.test 10;
  if (
this.test in {5,50,10})
  {
    echo(
"Test 2 true");
  }


This would echo true as this.test is contained within the array. This method can also work like this:
PHP Code:

function onCreated()
{
  
this.food "pizza";
  if (
this.food in {"pizza","pie","banana"})
  {
    
printf("I like %s",this.food);
  }


This method would print "I like pizza" since pizza was in the array. Hope this helps :D.

DustyPorViva 06-10-2007 03:32 AM

Doesn't quotations turn it into a string?
So extent = "32 32"; would be a string so you wouldn't be able to access it as an array, so:
if (extent[1]==32)
would be false. extent = {32,32}; would be an array, so
if (extent[1]==32)
would return true.

Twinny 06-10-2007 03:41 AM

Running this script,
PHP Code:

//#CLIENTSIDE
function onCreated()
{
  if (
window != NULLwindow.destroy();
  new 
GuiWindowCtrl("window")
  {
    
position = {5,5};
    
extent = {300,250};
  }
  echo(
" ");
  echo(
" ");
  
printf("Co-ords: %i %i",window.position[0],window.position[1]);
  
printf("Extent: %i %i",window.extent[0],window.extent[1]);
  
window.destroy();
  new 
GuiWindowCtrl("window")
  {
    
position "5 5";
    
extent "300 250";
  }
  
printf("Co-ords: %i %i",window.position[0],window.position[1]);
  
printf("Extent: %i %i",window.extent[0],window.extent[1]);


prints out
PHP Code:

Co-ords5 5
Extent
300 250
Co
-ords5 5
Extent
300 250 

in the F2 menu. So I guess not >_<.

Angel_Light 06-10-2007 03:48 AM

does printf even work in graal o.O

Twinny 06-10-2007 04:10 AM

Quote:

Originally Posted by Angel_Light (Post 1316748)
does printf even work in graal o.O

Yes, yes it does. It's an echo(format()); in one :D. It recently had a problem involving loops but I showed Stefan and he got it fixed. Use printf like you would use a format e.g.

PHP Code:

printf("Hi there %s, I have %i %s"player.account5"apples"); 

I love it :D

Inverness 06-13-2007 03:39 AM

Quote:

Originally Posted by Twinny (Post 1316757)
Yes, yes it does. It's an echo(format()); in one :D. It recently had a problem involving loops but I showed Stefan and he got it fixed. Use printf like you would use a format e.g.

PHP Code:

printf("Hi there %s, I have %i %s"player.account5"apples"); 

I love it :D

Ugh, I would have loved to have known this sooner >_>

extent = "32 32";

That format is for compatibility with Torque GUI script.

I also learned something about object types, apparently the static variables can have internalized functions for reading and writing them, which is why either format works I believe.

zokemon 06-14-2007 02:52 AM

You can also do like:
NPC Code:
if (player.x in <16,19>) {
bleh();
}


Which would be true if the number is in between 16 and 19 but would be false if it was exactly 16 or 19 (so 16.1 and 17 would be true but 15 and 16 would be false).

You can also do:
<16,19|
|16,19>
Respectively.

Having a good knowledge of geometry helps in this (I think that is the math subject that teaches rays and all that in a number line).

Twinny 06-14-2007 09:41 AM

Quote:

Originally Posted by zokemon (Post 1317817)
Having a good knowledge of geometry helps in this (I think that is the math subject that teaches rays and all that in a number line).

*Hisses and jumps out the window*


All times are GMT +2. The time now is 07:00 PM.

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