Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   [Tutorial] Simple Scripting Lessons - Preparations (http://forum.fulqrumpublishing.com/showthread.php?t=28997)

FG28_Kodiak 01-10-2012 07:31 PM

[Tutorial] Simple Scripting Lessons - Preparations
 
After looking into the posibilities of using triggers on Cliffs of Dover without scripting (http://forum.1cpublishing.eu/showthread.php?t=28454) , in this lesson we will make some preperations to make scripting easier for us.

When scripting in Cliffs of Dover, we will be using C# (C Sharp) (http://en.wikipedia.org/wiki/C_Sharp...mming_language). This has some advantages, but also some disadvantages. The advantages are that one doesn't have to learn a programming language which was specificaly designed for CloDo. There are enough books and pages on the internet which can be helpful in learning the language. Also, one can use all the posibilieties of .Net. The disadvantages are that especially beginners (I just wanted a victory message!) can be shocked by the posibilites of scripting. The commands are cryptical in part, and that the language is object-oriented doesn't make it easier. Although, beginners will probably have the most problems with missing semicolons or wrongly placed brackets.

Because of this, at first, we will have a look at the Editor which is integrated into Cliffs of Dover. Sadly, it neither supports syntax highlighting nor aumotatic intenting. Basicly, it offers less than Windows Notepad.
http://img12.imageshack.us/img12/6449/il2edi01.jpg

Although, one can open a menu by right clicking which can compile the code. This can be useful when searching for mistakes. As an example, in this code a semicolon was forgoten, and then the code was compiled:
http://img221.imageshack.us/img221/1806/il2edi02.jpg

As expected, the output window shows us an error message:
http://img13.imageshack.us/img13/768/il2edi03.jpg

Now we correct the missing semicolon and try it again:
http://img861.imageshack.us/img861/8674/il2edi04.jpg

Now everything seems to be all right:
http://img62.imageshack.us/img62/6740/il2edi05.jpg

After saving, the CloDo editor automaticaly creates a file with the ending "cs". Script files in Cliffs of Dover have to have the same name as the mission file, but with the ending "cs" instead of "mis".
http://img16.imageshack.us/img16/5292/filesi.jpg

As one can see, Cliffs of Dover doesn't offer to much help with scripting. Because of this, one should look for alternatives to the integrated editor. There are two posibilites: One can use an extended editor, like the freeware Notepad++ http://notepad-plus-plus.org/. It offers syntax highlighting and automated intenting, at least.
http://img221.imageshack.us/img221/3...epadplusqh.jpg

Or one gets a professional developing environment. In this case we are lucky, as Microsoft offers one free of charge (registration is requiered though), namely Microsoft Visual C# Express
http://www.microsoft.com/visualstudi...csharp-express

Especially for beginners, I would recommend downloading and installing this package, because the editor offers a lot of funtions which make programming a lot easier. Syntax errors are shown directly in the editor by a red marking, for example.
http://img833.imageshack.us/img833/8819/mswebsite.jpg

After downloading and installing Microsoft Visual C# Express, we start a new project.
http://img546.imageshack.us/img546/4431/visual01.jpg

In the window which now pops up, we choose "Class Library" and enter a fiting name for our "project", as we will loose track at "ClassLibrary10", at the latest. Now we click OK.
http://img859.imageshack.us/img859/9113/visual02.jpg

Express now creates all necessary files and opens the editor. The code lines which are already in there can be deleted, as we don't need them.
http://img534.imageshack.us/img534/1905/visual03.jpg

We simply replace them with the standard framework (more of that in the next lesson), which is needed to script a mission.
http://img16.imageshack.us/img16/498...sframework.jpg

After adding it, the Express editor already shows us the first errors. "The type or Namespace ...". This means, that the developing environment doesn't know the used assemblies (http://en.wikipedia.org/wiki/.NET_assembly). To change that, we select "References" in the Solution Explorer (orange arrow) and click it with the right mouse button.
http://img210.imageshack.us/img210/3918/visual04.jpg

Now we click "Add References"
http://img3.imageshack.us/img3/4233/visual05.jpg

In the dialogue box we choose "Browse" and navigate to the folder ..\Steam\SteamApps\common\il-2 sturmovik cliffs of dover\parts\core and highlight the files "antlr.runtime.dll", "core.dll", "gamePages.dll", "gamePlay.dll", "gameWorld.dll", "HostView.dll", "maddox.dll", "part.dll", "sound.dll" and "Strategy.dll"
http://img859.imageshack.us/img859/6223/visual06.jpg

and in the folder ..\Steam\SteamApps\common\il-2 sturmovik cliffs of dover\parts\bob the files "partBob.dll" and "Campaign.dll". We don't need all of them, but it doesn't hurt to add them to the project so we don't have to look for them later, if we might need them.
http://img163.imageshack.us/img163/8397/visual07.jpg

To call up another useful tool of the Express Editor, namely the Object-Explorer, we switch the Editor into expert mode.
http://img52.imageshack.us/img52/8175/visual08.jpg

Now we activate the Object-Browser (and yes, a simple "CTRL+W, J would have done the job, too)
http://img502.imageshack.us/img502/9384/visual09.jpg

In the Object-Explorer we can look more closely at the classes which are present in the Dlls.
http://img337.imageshack.us/img337/5608/visual10.jpg

The Express Editor also has the useful function autocomplete at it's disposal.
http://img27.imageshack.us/img27/9454/visual11.jpg
http://img855.imageshack.us/img855/2632/visual12.jpg

In the next lesson we will finally start with scripting - I promise!

Suggestions or criticism are always welcome.

Thanks again to FG28_Elatan for the translation.

KDN 01-10-2012 08:25 PM

Keep it coming ...if possible :)
I got Visual C sharp installed and got a dummies book along with another one that takes a littel different approach and have started getting into it but since I have no reference "pegs" my motivation is kind of ...limp!!
You have given me something to build on since it is CoD related, now I can go back with more enthusiasm.
Cheers!!

Smokeynz 01-10-2012 10:26 PM

I downloaded and installed the ms express editor, as a newbie to C# the editor has alot of advantages. I recommend getting it.

As noted it finds missing brackets and colons and basic syntax errors, however it does not see many other errors

Something I get caught up in with clod is exchanging information, passing data from one section to another. common error is "cannot covert "int" to "bool""

Although C# has a reasonble learning curve, maybe list commonly used elements with relation to clod as it stands, maybe why they are there.

examples,
using system xxxxx

main class
Amission

int
pvt int
bool
string

advance stuff
indexing
switches

Ataros 01-11-2012 08:39 AM

Great work as usual! Thank you very much for going into all the details!

Ataros 01-11-2012 08:45 AM

Quote:

Originally Posted by KDN (Post 378182)
I got Visual C sharp installed and got a dummies book along with another one that takes a littel different approach and have started getting into it but since I have no reference "pegs" my motivation is kind of ...limp!!

You can try starting making your own simple mission based on these scripts http://forum.1cpublishing.eu/showthread.php?t=26523 Or just study those scripts for starters and use your textbook to find answers when you are lost.

It is much more fun to work with CloD related code.

Pato Salvaje 01-11-2012 12:26 PM

OOOOOOHHHH!!!! MY GOD!...

Kodiak, you´ve made my day!! I was learning by my own, but this is a great step forward for me!!!... please keep coming...
I have MS express ready and waiting to script... ;-)

salmo 01-11-2012 01:25 PM

<Post deleted .... problem fixed> Thanks Kodiak for a useful tutorial :)

SG1_Lud 01-11-2012 02:14 PM

Awesome! TY very much Kodiak.
S!

Blackdog_kt 01-28-2012 07:52 PM

I've started a computer science course this year and we're learning Java, which is very similar in syntax and "mentality" to C#.

I've got a couple of exams to end this semester and then a 3 week break, i think i'll try to make something CoD related during the break.

For me the biggest issue is that i don't have knowledge of the libraries. I mean, i have a rough dynamic campaign structure in my head for online play that will support tracking of supplies for each side, but i don't know if/what kind of classes, methods and objects already exist in what the sim gives us.

If i had a brief explanation of what the provided classes/methods do in the game's .dll libraries i'd probably be able to get right down to making something useful and testing it.

SiThSpAwN 03-29-2012 04:23 PM

Great stuff, looking forward to more!!

moggel 04-01-2012 08:43 PM

I'm experienced with VS and C# and got exited to realize scripting is done in my "native language". Are there any dokumentation for the libraries that I can explore?

Thanks

FG28_Kodiak 04-01-2012 10:01 PM

No, not at the moment.

moggel 04-02-2012 08:09 AM

Too bad. Is there any word from Oleg et. al. when their API will be officially "released" (documented)?

Until the, I very much look forward to your upcoming tutorials! :-)

Cheers

FG28_Kodiak 04-02-2012 08:45 AM

At the moment the API seems unfinished like the other parts of the game. So may be in the Future :rolleyes:

moggel 04-03-2012 09:46 PM

Just a quick question Kodiak: Is it possible to debug using VS2010? That is, can I attach to a CLOD process (if so, which one) and set breakpoints in the code in order to examine what happens when?

FG28_Kodiak 04-04-2012 04:22 AM

No, its not possible.

moggel 04-04-2012 09:29 AM

Ok, I suspected as much. I suppose one is down to "poor man's debugging" using a textual log or something then to figure it all out...

moggel 04-08-2012 10:40 AM

Console Window
 
Me again... :grin:

I'm into scripting now and things are slowly starting to fall into place. I've experimented with triggers, got some planes to drop a wing and so on, all in the good name of exploration. :-P

However, I really do miss the ability to write some output into a console window. I've seen several scripts that write to the normal System.Console and since it's possible to configure an "Info Window" to write "Console Output" I thought I had found the way to do it. However, the only stuff that goes into such an Info Window is the stuff written by the game engine it seems. I never see any of my own stuff ending up in there.

Is there some neat trick I need to know about in order to make use of System.Console? Why else do script authors bother to write to the System.Console?

FG28_Kodiak 04-08-2012 10:54 AM

you can write things into console with
example:
GamePlay.gpLogServer(null, "Teststring", null);

Explanation
void gpLogServer(Player[] to, string format, object[] args);
first argument is the addressat.
null = all can read it.
new Player[]{ player} = single player
or Array of players, which will get the message

second parameter is the Message itself.

third parameter are additional values.
null = none.
new object[]{ value1, value2}
example:
GamePlay.gpLogServer(null, "Red has {0} Points, Blue has {1} Points", new object[]{redpoints, bluepoints});

moggel 04-08-2012 11:15 AM

Works perfectly! Thanks mate.

BTW: In C# you can initialize arrays implicitly:
GamePlay.gpLogServer(null, "Red has {0} Points, Blue has {1} Points", new[] {redpoints, bluepoints});

Cheers

moggel 04-08-2012 07:31 PM

Dynamic spawning?
 
Ok, another one:

I have found no way to dynamically create an AiActor and spawn it from my script. Is it not possible? If so, how does all those wonderful dynamic campaigns work?

FG28_Kodiak 04-08-2012 07:43 PM

1 Attachment(s)
No it's not possible directly but you can create a "in memory" mis - file. And load it to the main mission.

for example
Code:

internal ISectionFile CreateNewPlaneAtAirfield()
        {
            ISectionFile f = GamePlay.gpCreateSectionFile();

            f.add("AirGroups", "BoB_LW_StG2_II.03", "");
            f.add("BoB_LW_StG2_II.03", "Flight0", "1 2 3 4 5 6");
            f.add("BoB_LW_StG2_II.03", "Class", "Aircraft.Ju-87B-2");
            f.add("BoB_LW_StG2_II.03", "Formation", "VIC");
            f.add("BoB_LW_StG2_II.03", "CallSign", "30");
            f.add("BoB_LW_StG2_II.03", "Fuel", "100");
            f.add("BoB_LW_StG2_II.03", "Weapons", "1");
            f.add("BoB_LW_StG2_II.03", "SetOnPark", "1");
            f.add("BoB_LW_StG2_II.03", "Idle", "1");
            f.add("BoB_LW_StG2_II.03", "Skill", "0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3");
            f.add("BoB_LW_StG2_II.03_Way", "TAKEOFF", "298417.47 127327.45 0 0");

            return f;
        }

Then you can load it with
Code:

GamePlay.gpPostMissionLoad(CreateNewPlaneAtAirfield());
For more example take a look on
Tanks from narvy (added as atachment)

moggel 04-08-2012 08:29 PM

Nice...

I think using a more or less textual declaration like that is even more powerful (and elegant) than pure code.

Thanks again!

Smokeynz 04-14-2012 04:42 AM

Just note Kodiak,
There is a syntax error in this line in your example
ISectionFile f = gamePlay.gpCreateSectionFile();

Should be this, capital G
ISectionFile f = GamePlay.gpCreateSectionFile();

Oh from your example above I managed to create random generating flight including plane types, numbers and skills that is a response trigger loc to player and army specific. Still work in progress, but the basic script is working.:-P

FG28_Kodiak 04-14-2012 05:45 AM

Quote:

Originally Posted by Smokeynz (Post 409012)
Just note Kodiak,
There is a syntax error in this line in your example
ISectionFile f = gamePlay.gpCreateSectionFile();

Should be this, capital G
ISectionFile f = GamePlay.gpCreateSectionFile();

Corrected, thanks.

SG1_Lud 07-18-2012 10:38 AM

Hi Kodiak, first of all many thanks for your presentation and introduction.


I have some questions, sorry if it is too basic but I am starting to learn.

Where can I know the definition of the object type ISectionFile, I mean, all the fields that contains the different data fos setting up the new actor?

My second question, the list of groups like BoB_LW_StG2_II.03?

and finally, the list of callsigns associated to their codes (in the case above, was 30)?

S!

FG28_Kodiak 07-18-2012 11:34 AM

Quote:

Originally Posted by SG1_Lud (Post 446040)
Where can I know the definition of the object type ISectionFile, I mean, all the fields that contains the different data fos setting up the new actor?

Make a little Mission, then open the mis file, there are all informations you need:

for example in mis file:
[AirGroups]
BoB_LW_KG3_I.01
[BoB_LW_KG3_I.01]
Flight0 1
Class Aircraft.He-111H-2
Formation LINEABREAST
CallSign 26
Fuel 100
Weapons 1
SetOnPark 1
Idle 1
Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
[BoB_LW_KG3_I.01_Way]
TAKEOFF 40064.00 20458.26 0 0

internal ISectionFile CreateNewPlaneAtAirfield()
{
ISectionFile f = GamePlay.gpCreateSectionFile();

f.add("AirGroups", "BoB_LW_KG3_I.01", "");
f.add("BoB_LW_KG3_I.01", "Flight0", "1");
f.add("BoB_LW_KG3_I.01", "Class", "Aircraft.He-111H-2");
f.add("BoB_LW_KG3_I.01", "Formation", "LINEABREAST");
f.add("BoB_LW_KG3_I.01", "CallSign", "30");
f.add("BoB_LW_KG3_I.01", "Fuel", "100");
f.add("BoB_LW_KG3_I.01", "Weapons", "1");
f.add("BoB_LW_KG3_I.01", "SetOnPark", "1");
f.add("BoB_LW_KG3_I.01", "Idle", "1");
f.add("BoB_LW_KG3_I.01", "Skill", "0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3");
f.add("BoB_LW_KG3_I.01_Way", "TAKEOFF", "298417.47 127327.45 0 0");

return f;
}

Quote:

My second question, the list of groups like BoB_LW_StG2_II.03?
Don't know if there is a list of all Airgroups available, simplest solution create a mission with all Airgroups you need, then open the mis file.

Quote:

and finally, the list of callsigns associated to their codes (in the case above, was 30)?
Callsigns are available from 0-35 (german, italian beginning with Adler, english with Acorn) but don't think there is a complete list present, never needed one :rolleyes:

SG1_Lud 07-18-2012 12:10 PM

Many thanks Kodiak, very helpful.

WhiskeyBravo 08-21-2012 02:46 PM

Excellent tutorial for a total C# noob like me.

Any signs of the next lessons yet?

Many thanks,

WB.

FG28_Kodiak 08-23-2012 05:27 AM

After my vacation i will publish the next lessons ;)

WhiskeyBravo 08-23-2012 09:02 AM

Great news.

Enjoy your holiday.

WB.

SlipBall 09-08-2012 06:07 PM

@Kodiak
Great thread for me to learn how to make improved missions, thank you!...looking forward to the next lesson, I can't seem to get the basics. For example you can't paste in fmb, the script examples given in the other threads?...

edit:
Okay found Ataros wonderful guide and I am understanding better the how to. The "start airgroup engines" works great!

He111 09-16-2012 05:18 AM

Thanks kodiak and all .... hmm should I get back into C# ?? I enjoyed C some 20 years ago but C++ did my head in! LOL!

I think I'll see what the next patch brings, and how far i can get creating scenarios just through FMB.

.

SlipBall 09-19-2012 10:37 AM

Microsoft Visual Studio 2010 has a service pack 1 available for it, if you don't already have it, go to ms site.:cool:

marcastel57 12-27-2012 07:54 AM

Quote:

Originally Posted by FG28_Kodiak (Post 378170)
In the next lesson we will finally start with scripting - I promise!

Just great and very easy to follow. But....where are the other lessons?


All times are GMT. The time now is 03:42 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.