Accueil Crush your enemies... and create an EMPIRE!!! Space Empires V -- BUY NOW!!!

Connexion utilisateur

  • Créer un nouveau compte
  • Demander un nouveau mot de passe

Navigation

  • news
    • archive
    • blogs
    • books
    • forums
    • recent posts
    • groups
  • image galleries
  • projects & downloads
  • search
  • create content
  • agrégateur de nouvelles

Rechercher

Qui est en ligne

Il y a actuellement 1 utilisateur et 189 invités en ligne.

Utilisateurs en ligne

  • Bones

Languages

  • English English
  • French French

Parcourir les archives

« July 2008  
Mo Tu We Th Fr Sa Su
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Accueil » news » forums » Space Empires V » Space Empires V General

AI Scripting Technical Details

Soumis par Hearteater le Ven, 2008-05-16 15:39 Space Empires V General

I have a few quick technical questions I was hoping someone here about might have the answers to:

Do conditional operators (and, or) overload?

Can you have multiple exitwhen clauses in a loop?

Can you use a return statement to exit a function early?

Any problems with not covering all the cases in a case statement? Is there even a default mechanism?

Should lists be cleared before use?

Must locally declared lists be cleared prior to function exit?

Does Sys_AI_Setup_Select_Racial_Trait fail safely (does nothing) if the trait has already been added?

Am I just missing it, or is Sys_Iifreal the only default trigraph function?

Is there implicit type conversion from long to real? real to long?

Is there some purpose I'm not seeing to the various operator simulating functions (Sys_Long_Add and such)?

Thanks in advance.

‹ Weapons and damage A Question About Taking Planets Over... ›
» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Options d'affichage des commentaires

Sélectionnez la méthode d'affichage des commentaires que vous préférez, puis cliquez sur "Sauvegarder les paramètres" pour activer vos changements.
Mod Designer

Re: AI Scripting Technical Details

Soumis par Fyron le Ven, 2008-05-16 16:02

Hearteater wrote:
Do conditional operators (and, or) overload?
You may be expecting a little much here if you are looking to overload operators..

Hearteater wrote:
Can you use a return statement to exit a function early?
No. Return is a fucking lie; all it does is set a value to be returned, but it doesn't actually return from the function.

Hearteater wrote:
Should lists be cleared before use?
A new list wouldn't have anything to clear, but a list already containing data should probably be cleared..

Hearteater wrote:
Is there implicit type conversion from long to real? real to long?
Not that I'm aware of.

Hearteater wrote:
Is there some purpose I'm not seeing to the various operator simulating functions (Sys_Long_Add and such)?
If you can see purpose behind many of the things MM has put into this language, more power to ya.


SpaceEmpires.net | Space Empires Wiki

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Re: AI Scripting Technical Details

Soumis par Hearteater le Ven, 2008-05-16 20:06

Quote:
You may be expecting a little much here if you are looking to overload operators..
Oops, my mistake. I meant short-circut. Tried writing that too quickly and the wrong words came out.

» Vous devez vous identifier ou créer un compte pour écrire des commentaires
Mod Designer

Re: AI Scripting Technical Details

Soumis par Fyron le Sam, 2008-05-17 02:34

What do you mean by short-circuit?


SpaceEmpires.net | Space Empires Wiki

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Re: AI Scripting Technical Details

Soumis par Hearteater le Sam, 2008-05-17 06:08

if (FALSE and abc()) then
  ...
endif

That code would NOT call function abc() if the and operator short-circuts. In other words, since it is impossible for the statement to be true once the first half is false, the second half is skipped. Similarly, the or operator short-circuts if the first condition is true, skipping evaluating the second since that cannot make the statement false. That in a nutshell is short-circut evaluation.

Simple example, suppose I have stringlist and I need to search if it contains a specific string but only if I'm at war. Depending on short-circut evaluation I would write:

vars
  wars:   long
  value:  string
  list:   stringlist

...

// With short-circut evaluation:
if (wars > 0 and list.indexof(value) <> 0) then
  ...
endif

// Without short-circut evaluation:
if (wars > 0) then
  if (list.indexof(value) <> 0) then
    ...
  endif
endif

In both cases I'm skipping searching the list unless I really need to.

» Vous devez vous identifier ou créer un compte pour écrire des commentaires
Image de Captain Kwok
Mod Designer

Re: AI Scripting Technical Details

Soumis par Captain Kwok le Sam, 2008-05-17 09:24

The script would evaluate all conditions.


Space Empires Depot | SE:V Balance Mod

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Re: AI Scripting Technical Details

Soumis par Hearteater le Dim, 2008-05-18 21:32

Just combining everything from above and some of my own research into the following answers:

Q: Do conditional operators (and, or) use short-circuit evaluation?

A: No.

--

Q: Is AND higher precedence than OR?

A: No. These operators are of the same precedence and parsed in strict left-to-right fashion.

--

Q: Can you have multiple exitwhen clauses in a loop?

A: Yes.

--

Q: Can you use a return statement to exit a function early?

A: No. The return statement only sets the value to eventually be returned. Return could be viewed as "set return_value := xxx" with each function having an implicit "return return_value" at the end.

--

Q: Any problems with not covering all the cases in a case statement? Is there even a default mechanism?

A: No. Uncovered cases do nothing. There is apparently no default case.

--

Q: Should lists be cleared before use?

A: No, at least the default SE5 scripts don't.

--

Q: Must locally declared lists be cleared prior to function exit?

A: No, at least the default SE5 scripts don't.

--

Q: Does Sys_AI_Setup_Select_Racial_Trait fail safely (does nothing) if the trait has already been added?

A: <...Research Pending...>

--

Q: Am I just missing it, or is Sys_Iifreal the only default trigraph function?

A: That appears to be the only one.

--

Q: Is there implicit type conversion from long to real? real to long?

A: No and No. All type convertions must be explicit.

--

Q: Is there some purpose I'm not seeing to the various operator simulating functions (Sys_Long_Add and such)?

A: No known reason.

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Re: AI Scripting Technical Details

Soumis par weregamer le Dim, 2008-06-15 17:50

OK, if all type conversions must be explicit, where is the long-to-real conversion? SyS_Trunc and Sys_Round are fine for real-to-long, but I don't see anything for the other way...

» Vous devez vous identifier ou créer un compte pour écrire des commentaires
Image de Captain Kwok
Mod Designer

Re: AI Scripting Technical Details

Soumis par Captain Kwok le Dim, 2008-06-15 18:27

There isn't one, but you could use real_var := long_var * 1.0 etc.


Space Empires Depot | SE:V Balance Mod

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Re: AI Scripting Technical Details

Soumis par weregamer le Lun, 2008-06-16 02:09

Weird. myreal := mylong won't work but myreal := 1.0 * mylong will? Or was the earlier claim that implicit conversion is not supported either way overzealous.

Anyway, what I need to do will work fine in any case. Thanks.

» Vous devez vous identifier ou créer un compte pour écrire des commentaires

Options d'affichage des commentaires

Sélectionnez la méthode d'affichage des commentaires que vous préférez, puis cliquez sur "Sauvegarder les paramètres" pour activer vos changements.

Now on STEAM

Now on STEAM!Space Empires V via STEAMSpace Empires IV via STEAMSTEAM online by Valve Corporation

Contenu populaire

Aujourd'hui :

  • I am so impressed!
  • Space Empires V 1.74
  • Neutral pack 1.10 released, now adds three neutral races.
  • Stuipd Question
  • Research By Percentage SUCKS

Depuis toujours :

  • Space Empires V and VI: Expansions and the Future: Tell the Company What's on Your Wish List
  • Space Empires V
  • Gritty Galaxy Fleet Clash
  • Damn Dirty Bugs/Annoyances
  • Space Empires V: General Thoughts, Observations, and Suggestions

Dernier accès :

  • Sys_Set_AI_Storage_Long Problems
  • My Mod and Spaceport
  • New Game using Exodus mod
  • Ground Combat Error
  • Cloaking Problem
(c) Strategy First, Inc. All rights reserved.