How to define a vector3 in unity3d using unityscript - vector

i am trying to define a vector3 in my unityscript.
I've already tried writing this:
cubeVector = vector(1,2,1)
Thank you,

In unity3D you can declare a Vector3 like this:
var myVector = Vector3(1,2,1);
Your code has the following faults:
You didn't write var before cubeVector
You didn't end your line with ;
Try also visiting the following page.

Related

In Godot the path returned by get_simple_path() seems offset by something

Just learning Godot, so maybe missing something obvious
I am trying to have the player navigate towards a point clicked on the map.
The path is calculated with some sort of offset I can't figure out.
Any pointers appreciated!
There is a very minimal replication of the problem here
https://github.com/kender99/Godot_path_finding_problem_demo
On the image the white dot is the mouse click and the red is the path generated
The likely offending code is:
extends Node2D
var path : = PoolVector2Array()
func _unhandled_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
path = $Navigation2D.get_simple_path($Player.position, event.position)
$Player.path = path
$Line2D.points = path
print(path.size(), ' Path:',path, ' Player:', $Player.position, ' Target:', event.position)
update() # so line and circles get drawn
func _draw():
for p in path:
draw_circle(p, 5, Color(200, 200, 200))
event.position is the local position regards the current respondent, you should convert the event position to the local one of Navigation2D instead, like this:
path = $Navigation2D.get_simple_path($Player.position, $Navigation2D.to_local(event.position))
or use get_global_mouse_position() method like this:
path = $Navigation2D.get_simple_path($Player.position, $Navigation2D.to_local(get_global_mouse_position()))

How to make an if statement point free

I have the following if statement:
var formatCity =
obj => R.both(has('city'), has('state'))(obj) ? appendCommaToCity(obj) : obj
I would like to make this code point free, but can not figure out a way around the if statement.
That's quite simple actually using the ifElse function - or its specialisation, when:
const formatCity = R.when(R.both(has('city'), has('state')), appendCommaToCity);

What's the difference manipulating display object position?

I have 2 possibilities. It looks like these are the same (or I'm wrong). Which is better and why?
var quest1:DisplayObject = FrameCanvas.baseCanvas.addChild(app.questionmark1); //
quest1.x = posX; //
quest1.y = posY; //
or
app.questionmark1.x = posX;
app.questionmark1.y = posY;
In the first example quest1 is a reference to app.questionmark1 which you are adding to FrameCanvas.baseCanvas and then updating its x and y.
In the second example you are directly setting the x and y on app.questionmark1.
Both work to update app.questionmark1's x and y properties, but in the second example app.questionmark1 may not be on the stage unless you added it somewhere else in the code.
The second example is better because there's really not a reason to store a reference to app.questionmark1 as quest1 as you already can access it by app.questionmark1.

How do I create variable paths using e4X?

I need to know how I can parse a variable path in Flex 3 & e4X. For example, I have two XML strings where the name of one element is the only difference.
<NameOfRoot>
<NameOfChild1>
<data>1</data>
</NameOfChild1>
</NameOfRoot>
<NameOfRoot>
<NameOfChild2>
<data>2</data>
</NameOfChild2>
</NameOfRoot>
Currently I am accessing variables like this:
var data1:String = NameOfRoot.*::NameOfChild1.*::data;
var data2:String = NameOfRoot.*::NameOfChild2.*::data;
I would rather make this task more abstract so that if "NameOfChild3" is introduced I do not need to update the code. For example:
var data:String = NameOfRoot.*::{variable}.*::data;
Does anyone have insights into how this can be done?
Use the child property (LiveDocs example here):
var tagName:String = "NameOfChild1";
var data:String = NameOfRoot.child(tagName).data;
That's with no namespacing--not sure whether it's necessary in your case, but I assume you'd add some *::'s?
this also works:
var data:String = NameOfRoot..data;
but if you have more than 1 data node you'll have to sort some stuff out.
It looks like the ".*." operation will work. I wonder if this is the easiest way to handle this problem.
var data:String = NameOfRoot.*.*::data;

In Flash, how would I run an e4x statement when that statement is stored in a String?

So I have something like this:
var xmlStatement:String = "xmlObject.node[3].#thisValue";
What mystery function do I have to use so that I can execute xmlStatement and get thisValue from that xmlObject? Like....
var attribute:String = mysteryFunction(xmlStatement);
P.S. I know eval() works for actionscript2, I need the as3 solution. :)
Unfortunately this is not possible in ActionScript 3. This however might be a solution: http://blog.betabong.com/2008/09/23/e4x-string-parser/
For your example it would be:
var attribute : String = String( E4X.evaluate( XMLList(xmlobject) , 'node[3].#thisValue' ) );

Resources