≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Custom class return value bug
Posted by:
(you are not logged in)
Enter the missing letter in: "?nternational"
(you are not logged in)
Text:
[quote][b]xanimalkingx[/b] wrote: I made a small vector2d class. When I print just the vector2d itself, I get a 3 point value despite the class only having a X and Y value. My class has no Z value or field, so its impossible to return a third value. Its default constructor insures that. For example: [code] var newVec = new vector2d(0.5, 0.5); print(newVec); [/code] Outputs: [code] 0.5, 0.5, 0.0 [/code] Where as: [code] var newVec = new vector2d(0.5, 0.5); print(newVec.x + ", " + newVec.y); [/code] Outputs: [code] 0.5, 0.5 [/code] Here is my class: [code] // vector2d class by xanimalkingx // Holds 2 points which can be used for things that require 2D coordinates, // such as texture coordinates. // (must be defined at start of file) vector2d = function(xVal, yVal) { // Constructor // Check for null if (xVal == null) { this.x = 0; } else { this.x = xVal; } if (yVal == null) { this.y = 0; } else { this.y = yVal; } // Set both points to new values this.set = function(newX, newY) { this.x = newX; this.y = newY; } // Set a new value for the x point this.setX = function(newX) { this.x = newX; } // Set a new value for the y point this.setY = function(newY) { this.y = newY; } // Clone this vector2d into a new variable this.clone = function() { return new vector2d(this.x, this.y); } } [/code][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact