### Author Topic: Lua scripting in Eufloria - reference  (Read 17132 times)

0 Members and 1 Guest are viewing this topic.

#### ulfn

• Guest
##### Re: Lua scripting in Eufloria - reference
« Reply #15 on: May 21, 2010, 06:26:26 PM »
Using the time-honored method of trial-and-error I found the following fields for the Asteroid type:

 Field type description position Position The position of the asteroid. radius float The radius of the asteroid. attribs Attributes Asteroid attributes (strength, energy, speed)

With the types

Position
 Field type x float y float

Attributes
 Field type strength float energy float speed float

The position and radius are really handy for instance for computing if one asteroid is reachable from another:
(click to show/hide)

Edit: The attribs and radius are in jh's userdata list, but the position field isn't.

#### Alex

• Ent
• Thank You
• -Given: 3
• Posts: 1,035
##### Re: Lua scripting in Eufloria - reference
« Reply #16 on: August 02, 2010, 09:47:48 PM »
Added to the list (these should be in and working in 2.05):
General game entities - these functions can be used on most anything in the game (seedlings, trees, asteroids, etc)
 Function name Return value Description SetVisible(int faction, bool visible) nil Sets whether the entity can be seen by the given faction. Regen(float time) nil tells the entity to regenerate some of its energy. The parameter is delta time, so set it to e.g. 1 to regenerate a second's worth of energy. Normally this is called once a frame with the duration of the frame passed in. DistanceSquaredTo(Entity other) float returns the squared distance from the centre of this entity to the centre of the one you passed in. AttackedBy(Entity other) nil Tells this entity that it was attacked by the one you pass in. AttackedBy(Entity other, float time) nil Tells this entity that it was attacked by the one you pass in for 'time' seconds. Normally the second value is the frame duration. Field name Type Description Position Vector3 Position of the entity - access individual coords with capital letters e.g. entity.Position.X or entity.Position.Y. Radius float radius of the entity. OnScreen bool tells you whether the entity is on the screen or not. Active bool Tells whether the entity is still active. Set it to false to remove the entity from the game.

#### IDemon

• Webdesigner/Developer and Magician
• Shoot
• Thank You
• -Given: 0
• Posts: 22
• Talent does what it can, Genius does what it must.
##### Re: Lua scripting in Eufloria - reference
« Reply #17 on: August 02, 2010, 11:32:20 PM »
Alex truly a massive thank you for publishing all this for us it has been no end of help in developing my map editor thus far.
Talent does what it can, Genius does what it must.

#### dragoonreas

• Seedling
• Thank You
• -Given: 0
• Posts: 35
• Eufloria: Yes
##### Re: Lua scripting in Eufloria - reference
« Reply #18 on: August 03, 2010, 01:18:59 PM »
I was looking through the userdata structures list jhchrist posted and noticed the get_FacingAngle and get_Rotation functions for Asteroids. I'm assuming the FacingAngle parameter controls the absolute rotation of the asteroid, and the Rotation parameter controls how fast and in what direction the asteroid is spinning. Are these assumptions correct?

I tried using GetAsteroid(id).FacingAngle but it didn't seem to do anything. I might have been setting the facing angle using radians rather then degrees, which may explain why it didn't appear to have any affect if it's supposed to be set using degrees.

I also tried using GetAsteroid(id).Rotation but got an error saying there was no Set function for this parameter. Does this mean that the asteroid rotation (spin) isn't bound in Lua, or is there another way to set it?

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Lua scripting in Eufloria - reference
« Reply #19 on: August 03, 2010, 01:21:17 PM »
Rotation doesn't work. I tried already, a while back.

Here's what Alex said:

...

for now, no rotating asteroids or even experiments with rotating asteroids - sorry!

#### dragoonreas

• Seedling
• Thank You
• -Given: 0
• Posts: 35
• Eufloria: Yes
##### Re: Lua scripting in Eufloria - reference
« Reply #20 on: August 03, 2010, 01:46:22 PM »
That's a shame, spinning asteroids would have looked cool in the level I'm making.

I think the FacingAngle still retained the value I gave it though, so at least I won't have to create a separate array to store the angle values I'm using for my tree fractal algorithm. I'll also be making use of that new DistanceSquaredTo function in my algorithm too.

EDIT: Nope, the FacingAngle parameter stays at 0 no matter what you set it to. The DistanceSquaredTo function is also not working for me, as I get the following error message when I try to use it "Object reference not set to an instance of an object."
« Last Edit: August 03, 2010, 07:59:23 PM by dragoonreas »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Lua scripting in Eufloria - reference
« Reply #21 on: August 04, 2010, 03:00:47 PM »
You CAN rotate asteroids, but the trees and shrubbery and seedlings and everything else do not rotate with it.  Therefore because asteroids are circular, it effectively does nothing.

#### spywhere

• Eufloria != Euroflia
• Seedling
• Thank You
• -Given: 1
• Posts: 27
• CEO of DP
• Eufloria: Yes
##### Re: Lua scripting in Eufloria - reference
« Reply #22 on: October 21, 2010, 02:21:39 PM »
Is "Globals.Flowers.MaxVolume" exist in the game?

I just make a commands database in my Tools and set default value as in the game and found that only one field is not used which is Globals.Flowers.MaxVolume

I use default.xml to set default value.

Thanks...

PS. Sorry for my bad English
Euroflia : Online graphic Eufloria level editor now temporary dropped...
http://sdcenter.ispace.in.th/euroflia
http://sdcenter.zoka.cc/euroflia

#### Alex

• Ent
• Thank You
• -Given: 3
• Posts: 1,035
##### Re: Lua scripting in Eufloria - reference
« Reply #23 on: October 27, 2010, 06:51:35 PM »
It does exist - it's used when flowers and mines are plucked, and for the flowers and mines loop sounds.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Lua scripting in Eufloria - reference
« Reply #24 on: December 20, 2010, 10:24:02 PM »
Alex, what does GetLeafColour(int) do?

I saw it in somebody's code.  I had no idea it was a command!  I gather it must be run on a tree.  What does it return?

If this could be used to check what colour a particular empire is, that would be very useful to me!

#### Alex

• Ent
• Thank You
• -Given: 3
• Posts: 1,035
##### Re: Lua scripting in Eufloria - reference
« Reply #25 on: December 21, 2010, 01:21:08 PM »
It's a function in "Structure" (i.e. trees), takes an integer from 0 to 4 inclusive and returns a colour. Each team has 5 colours that represent it, and trees store an internal version of it so that when tree ownership changes, the leaves that it bears can smoothly change colour instead of changing immediately.

If you want to get a team colour... here's a tasty bit for you.
Code: [Select]
`Game = luanet.import_type("Eufloria.ColonyGame");team1red0 = Game.GetFactionColour(1,0)team1red1 = Game.GetFactionColour(1,1)team4red3 = Game.GetFactionColour(4,3)`
luanet.import_type gives you access to a class type theoretically giving you the opportunity to create instances of this type as well, though I am not sure what it would mean to do this in many cases for Eufloria's classes.

GetFactionColour is a static function of ColonyGame so you only need the type to be able to access it, not the ColonyGame instance. Hence the code above assigns the type ColonyGame to the variable CG, and this makes available the static functions of that type.

The base game class (that handles the front end etc) is Eufloria.Game, and has a static instance called Eufloria.Game.Instance from which various things are available (including Game.Instance.ColonyGame if the game is running).

e.g.
Code: [Select]
`Program = luanet.import_type("Eufloria.Game")ProgramInstance = Program.InstanceGame = luanet.import_type("Eufloria.ColonyGame")GameInstance = ProgramInstance.ColonyGameif (GameInstance ~= nil) -- use some part of colonygame instance e.g. call ApplyDarkModeSettings()!`
All very untested and unsupported I must hasted to add!

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Lua scripting in Eufloria - reference
« Reply #26 on: December 21, 2010, 01:28:15 PM »
Can you set the colours with this too?

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Lua scripting in Eufloria - reference
« Reply #27 on: December 21, 2010, 02:13:20 PM »
Even with just what Alex has given me, I could effectively "set" colours.  I could develop a script that checks what the colour is, and changes the asteroid to a different empire number if it's a colour I don't like.  :>

This is freaking awesome... if it works, this will finally give me the ability to produce maps that look exactly how I intend them to look, every time they are played.  :>

#### Alex

• Ent
• Thank You
• -Given: 3
• Posts: 1,035
##### Re: Lua scripting in Eufloria - reference
« Reply #28 on: December 21, 2010, 03:00:30 PM »
I don't think you can set them at the moment, maybe there's a way but as ColorF (the data returned by GetFactionColour) is a struct not a class, you don't get passed back a reference, so going GetFactionColour(1,4).R = 0.8 won't do anything. Same for GetLeafColour. The changing empire plan ought to work though. Just bear in mind that the leaf colours may not be close to any of the team colours if the asteroid was recently taken over.

• Achiever
• Ent
• Thank You
• -Given: 0