Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2007, 03:17 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
{} 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.
__________________
Deep into the Darkness peering...
Reply With Quote
  #2  
Old 06-10-2007, 03:28 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 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 .
Reply With Quote
  #3  
Old 06-10-2007, 03:32 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #4  
Old 06-10-2007, 03:41 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
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 .
Reply With Quote
  #5  
Old 06-10-2007, 03:48 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
does printf even work in graal o.O
__________________
Deep into the Darkness peering...
Reply With Quote
  #6  
Old 06-10-2007, 04:10 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
Quote:
Originally Posted by Angel_Light View Post
does printf even work in graal o.O
Yes, yes it does. It's an echo(format()); in one . 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
Reply With Quote
  #7  
Old 06-13-2007, 03:39 AM
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
Quote:
Originally Posted by Twinny View Post
Yes, yes it does. It's an echo(format()); in one . 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
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.
__________________
Reply With Quote
  #8  
Old 06-14-2007, 02:52 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
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).
__________________
Do it with a DON!
Reply With Quote
  #9  
Old 06-14-2007, 09:41 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
Quote:
Originally Posted by zokemon View Post
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*
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 04:48 PM.


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