Page 1 of 2

Request explanation of a script topic

Posted: Sun Aug 17, 2008 3:39 am
by Betelgeuse
Here you can request a tutorial on some topic in scripts that doesn't already have a tutorial. Anything from functions to recursion to data storage to returning from functions and anything else you would want to see.

Remember for specific pieces of code you want help with please post in the help me thread (to be made later).

Posted: Sun Aug 17, 2008 10:52 pm
by Periculi
I want to check and see if a mod is loaded.

I tried to place a Global value in such as:

<Globals>
(block nil

(setq testMod "True")

)
</Globals>

And then in another extension, I simply checked the value of testMod-

(if (eq testMod "True")
(setq desc "mod is loaded")
)

This worked fine if the mod is there, but when the mod is not there it gives the error- no binding for testMod

Now, is there a way to check for testMod and avoid having the error show up on the screen? Can I use (isError to do that?

The point is to find an easy way to detect if certain mods are present- now I could use it on a system such as sysSetData- but then if the mod is used in an adventure extension that doesn't have the same nodeID the method breaks. I tried using a typSetGlobalData on a station, but if the station is in a different extension the game won't load.

Posted: Sun Aug 17, 2008 11:19 pm
by Betelgeuse

Posted: Thu Aug 21, 2008 1:33 pm
by digdug
Job list for script and functions:

- New 0.99x functions testers (please join the IRC channel for this)
Basically the job consist in helping to test the new functions and discover how they works


Moreover, you can propose yourself to write a tutorial on a script or a function you know ! Help the community grow (and mod) :D

Posted: Fri Aug 22, 2008 8:24 pm
by Periculi
Ugh, HELP!

(sysVectorRandom vector number number criteria)

Ok, I see in Huari.xml that George used "t" in criteria to set the uncharted gate.

Now, I thought that that was used for:
* t -> Include stations (including planets)

But the gate gets built in "deep space away from everything"

So, what is the filter doing in:
(sysVectorRandom Nil (random 1200 1500) 300 "t")


And is there a way to randomly choose a planet within a certain range using this function?

Posted: Fri Aug 22, 2008 8:34 pm
by george moromisato
Periculi wrote:Ugh, HELP!

(sysVectorRandom vector number number criteria)
(sysVectorRandom center radius minSeparation [filter]) -> vector

The goal of this function is to return a random position, X, such that:

1. X is 'radius' light-seconds away from 'center'
2. X is at least 'minSeparation' light-seconds away from any object that matches 'filter' criteria. If 'filter' is Nil, then we avoid all objects.

Posted: Fri Aug 22, 2008 8:39 pm
by Periculi
Oh, good. Same filters as sysFindObject searches then?

Posted: Fri Aug 22, 2008 9:45 pm
by george moromisato
Periculi wrote:Oh, good. Same filters as sysFindObject searches then?
Yes.

Posted: Sat Aug 23, 2008 12:15 am
by Periculi
I am not sure that works like I think it does.

If I use (sysVectorRandom nil 1000 10 "t") should I expect to get a random location in the middle of no where? How can I select a position near a planet?

Posted: Sat Aug 23, 2008 2:03 am
by george moromisato
Periculi wrote:I am not sure that works like I think it does.

If I use (sysVectorRandom nil 1000 10 "t") should I expect to get a random location in the middle of no where? How can I select a position near a planet?
Yes. (sysVectorRandom) is designed to find a spot that is not near anything. The "10" in your call is the minimum distance from any "t"; it is not the maximum distance. If you want to pick a random spot near a planet, you can use something like:

Code: Select all

(sysVectorRandom 
     (random (sysFindObject Nil "t")) 
     50
     10
     )
This will pick a random spot 50 light-seconds away from a random planet and not less than 10 light-seconds from any other object.

Posted: Sat Aug 23, 2008 2:25 am
by Periculi
Thanks again. :)

Posted: Sun Aug 24, 2008 12:39 am
by digdug
How do I check if a ship is attacking the playership ?

is there something like:
(sysFindObject gPlayerShip "O:attack")
:?:

Posted: Sun Aug 24, 2008 12:55 am
by Betelgeuse

Code: Select all

(filter (sysFindObject gPlayerShip "Es") enemyShip (eq (objGetTarget enemyShip) gPlayerShip))
gives you all the enemy ships currently attacking the player ship

but please for so specific topics please use the help me thread

Posted: Sun Aug 31, 2008 10:35 pm
by digdug
More than an explanation is a request:
I would like a list with all the hardcoded aGlobals and gGlobals that can be used for each event.

George kindly made a nice list for <OnDamage>:

Code: Select all

<OnDamage> Event
gSource = station object
aAttacker = object that attacked
aHitPos = vector position of hit
aHitDir = angle direction from which hit came
aDamageHP = hit points of damage
aDamageType = type of damage
What about the others ?

Posted: Mon Aug 31, 2009 9:49 pm
by Betelgeuse
a good tutorial would be on how to choose non flat random numbers.

One example would be making a curve with dice throws.
I would also like to see how to make a curve that as it closer to the maximum value it has a greater probability of being chosen.
Any other nice curves would be nice.

A general case method would be also wanted. Where you can give the chances for each value.