Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   textWidth help o.o (https://forums.graalonline.com/forums/showthread.php?t=134257669)

12171217 01-16-2010 02:27 AM

textWidth help o.o
 
PHP Code:

function showInterfaceButtons() {
  
temp.buttontext = {"New Scene""Save Scene""Load Scene""Help"};

  
temp.dx 4;

  for (
temp.i=0;temp.i<2;temp.i++) {
    
this.images++;
    
showText(this.imagestemp.dx4"Tahoma""i"temp.buttontext[temp.i]);
    
changeImgVis(this.images6);

    
this.images++;
    
showText(this.imagestemp.dx+26"Tahoma""i"temp.buttontext[temp.i]);
    
changeImgVis(this.images5);
    
changeImgColors(this.images0.250.250.251);

    
temp.dx += textwidth(1"Tahoma""i"temp.buttontext[temp.i]);
  }


Can somebody explain why that doesn't work correctly?

It's supposed to display them in order from left to right with the correct spacing in between. Doesn't work properly, unfortunately. TextWidth seems to be bugged up, unless, of course, I'm using it improperly.

xXziroXx 01-16-2010 02:30 AM

The correct function name would be 'gettextwidth'.

12171217 01-16-2010 02:36 AM

Thank you.

12171217 01-16-2010 03:05 AM

Does anybody know the equivalent of setArray for GS2?

xXziroXx 01-16-2010 03:14 AM

Quote:

Originally Posted by 12171217 (Post 1550591)
Does anybody know the equivalent of setArray for GS2?

this.array = new[#];

12171217 01-16-2010 03:20 AM

Quote:

Originally Posted by xXziroXx (Post 1550594)
this.array = new[#];

Fabulous. Thanks again.

Another question; I'm a GS1 buff, not a GS2 buff ;)

Can you create entirely new objects, and arrays of objects in GS2?

xXziroXx 01-16-2010 03:23 AM

Quote:

Originally Posted by 12171217 (Post 1550595)
Can you create entirely new objects, and arrays of objects in GS2?

Yes.

12171217 01-16-2010 03:39 AM

Quote:

Originally Posted by xXziroXx (Post 1550596)
Yes.

And the syntax would be? o.o

xXziroXx 01-16-2010 03:50 AM

Quote:

Originally Posted by 12171217 (Post 1550598)
And the syntax would be? o.o

Depends what you mean by "creating new objects" really. But, something along these lines:

PHP Code:

this.array = new[0];
this.array.add(this);  // Would add the current object into the array
this.array.add(findPlayer("xXziroXx"));  // Would add the player object (if online)

// The following example is the same as the above.

this.array = { thisfindPlayer("xXziroXx") };  // Would create a two sized array with the current object, as well as the object found by the findPlayer() function. 

Was that what you were looking for? :)

12171217 01-16-2010 03:57 AM

Quote:

Originally Posted by xXziroXx (Post 1550600)
Depends what you mean by "creating new objects" really. But, something along these lines:

PHP Code:

this.array = new[0];
this.array.add(this);  // Would add the current object into the array
this.array.add(findPlayer("xXziroXx"));  // Would add the player object (if online)

// The following example is the same as the above.

this.array = { thisfindPlayer("xXziroXx") };  // Would create a two sized array with the current object, as well as the object found by the findPlayer() function. 

Was that what you were looking for? :)

I meant it as far as doing something along the lines of defining data structures in C++.

PHP Code:

typedef struct {
  
float xyz;
3dpoint;

3dpoint cheeselocation;

cheeselocation.1;
cheeselocation.2;
cheeselocation.3

Can you do anything along the lines of that in GS2?

fowlplay4 01-16-2010 04:05 AM

You can be lazier! :)

PHP Code:

function onCreated() {
  
temp.obj = new TStaticVar();
  
temp.obj.1;
  
temp.obj.2;
  
temp.obj.3;



xXziroXx 01-16-2010 04:07 AM

I'm not really familiar with C++ (or many other languages), but if that's supposed to do what I think it is, the closest you'd find would be something like this:

PHP Code:

this.myobject = new TStaticVar("cheeselocation");

cheeselocation.foo "bar"


12171217 01-16-2010 04:08 AM

Quote:

Originally Posted by fowlplay4 (Post 1550602)
You can be lazier! :)

PHP Code:

function onCreated() {
  
temp.obj = new TStaticVar();
  
temp.obj.1;
  
temp.obj.2;
  
temp.obj.3;



Haha, perfect, thanks. :)

cbk1994 01-16-2010 04:34 AM

You can't make actual objects/object types, whatever you want to call them, but you can make TStaticVars, set variables, and join classes to them to do most of what you probably want to do.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
CheeseLocation = new TStaticVar();
  
CheeseLocation.join("CheeseLocation");


and in the class CheeseLocation:

PHP Code:

//#CLIENTSIDE
public function setPosition(xyz) {
  
this.position = {xyz};
}

public function 
getPosition() {
  return 
this.position;
}

// you can even do this to spoof it as an object even further, but there's no real reason to
public function objectType() {
  return 
"CheeseLocation";


Keep in mind there will be a delay between the time obj.join() is called and when the class is actually joined (it doesn't pause the script to wait for it to join).

You can also make new instances of the object you made.

PHP Code:

BigCheese = new CheesePosition();
BigCheese.setPosition(130);

SmallCheese = new CheesePosition();
SmallChese.setPosition(041); 

A bit of a workaround but it works.

EDIT: oops, didn't notice the second page of the thread

12171217 01-16-2010 04:40 AM

Thanks anyway, Chris. I appreciate it regardless.


All times are GMT +2. The time now is 01:29 AM.

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