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

User login

  • Create new account
  • Request new password

Navigation

  • news
    • archive
    • blogs
    • books
    • forums
    • recent posts
    • groups
  • image galleries
  • projects & downloads
  • search
  • create content
  • news aggregator

Search

Who's online

There are currently 5 users and 190 guests online.

Online users

  • inertiatic
  • GambitUK
  • crazydog
  • Theace
  • bauscho

Languages

  • English English
  • French French

Browse archives

« Septembre 2008  
Lu Ma Me Je Ve Sa Di
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          
Home » news » forums » Space Empires V » Space Empires V General

AI Scripting Technical Details

Submitted by Hearteater on Fri, 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... ›
» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mod Designer

Re: AI Scripting Technical Details

Submitted by Fyron on Fri, 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

» login or register to post comments

Re: AI Scripting Technical Details

Submitted by Hearteater on Fri, 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.

» login or register to post comments
Mod Designer

Re: AI Scripting Technical Details

Submitted by Fyron on Sat, 2008-05-17 02:34.

What do you mean by short-circuit?


SpaceEmpires.net | Space Empires Wiki

» login or register to post comments

Re: AI Scripting Technical Details

Submitted by Hearteater on Sat, 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.

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: AI Scripting Technical Details

Submitted by Captain Kwok on Sat, 2008-05-17 09:24.

The script would evaluate all conditions.


Space Empires Depot | SE:V Balance Mod

» login or register to post comments

Re: AI Scripting Technical Details

Submitted by Hearteater on Sun, 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.

» login or register to post comments

Re: AI Scripting Technical Details

Submitted by weregamer on Sun, 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...

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: AI Scripting Technical Details

Submitted by Captain Kwok on Sun, 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

» login or register to post comments

Re: AI Scripting Technical Details

Submitted by weregamer on Mon, 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.

» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Now on STEAM

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

Popular content

Today's:

  • Babylon 5 Space Empires V mod?
  • Balance Mod v1.05 Available!
  • Killing crew
  • Ship Capture Issues
  • Space Empires V

All time:

  • 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

Last viewed:

  • weapon platform targeting issue
  • Colony air logic
  • Looks Like the Patch is Out
  • Possible to bring supply freighter with a fleet?
  • 1.10 Changelog
(c) Strategy First, Inc. All rights reserved.