scrpiting problums

Forum Archive - from http://theuniversal.net
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

scrpiting problums

Post by MasterNiCron »

first of all note pad cant save files as .mit

secand i get the comands and all i just dont get the ( ) { } [ ] " " and the odd spaceing that comes with them

forenstance

Code: Select all

Event( “NewBuilding”, “3” ) 
{ 
  *say %PLAYER% built building 3 
  *grantitem %PLAYER% Special Item
} 
i get that this gives a item and says some thing for building a sertan building but dont get what all the

{


}
i looked all over http://theuniversal.net/worldmanual/doku.php?id=index but found nuthing about the spaceing or comas or the perenthises
User avatar
XmAkInA
Posts: 45
Joined: Fri Oct 08, 2004 10:37 pm
Location: Omnicron Towers
Contact:

Post by XmAkInA »

Get yourself a better app like Notepad++

Curly brackets are routinely used in scripting languages to denote functions e.g.

Code: Select all

HelloWorld()
{
    alert("hello world!");
}
The reason you didn't find anything explaining them is because the samples section of the wiki seems to be empty.

Parenthesis like () are usually used to pass in arguments e.g.

Code: Select all

Hello(message)
{
    alert("Hello " + message);
}
Honestly if you're this new to programming, get yourself over to http://www.codecademy.com/ and learn some of the basics there
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Here you're into territory that "won't need any explanation providing you're already familiar with a language like C".. as i've been so for the last 20 years or so its not something i thought of documenting :)

So... lets look at the first bit

Code: Select all

Event( "NewBuilding", "3" )
This is the bit that defines the event.. i.e. it tells the server that there follows a bit of code that needs to get run when this particular event occurs. The formatting of that line is part of the language specification. The spaces don't matter really (they're just there to make things look neat).

The important parts to that line are first the word "Event" which says 'Here comes a bit of code for an 'Event' '. Coz its an event the server expects to find some parameters in brackets straight after. The parameters in brackets define the type of event.
In this case, its saying the event name is "NewBuilding", and the second parameter (in the case of a 'NewBuilding' event) specifies the building type number.
In summary.. the line above says "There follows a bit of code that should be run whenever a new building (of type 3) is created".

The { } brackets set out the block of code that should be run for that event. Once its recognised the Event line, the server looks for a {, then runs through all the statements until it finds a corresponding }

as an example, suppose the code looked like this

Code: Select all

Event( “NewBuilding”, “3” ) 
{ 
  *say Message 1
  *say Message 2
} 
*say Message 3
then the output would be 'Message 1' then 'Message 2' but 'Message 3' would not get printed. (As that line is outside of the code block defined by the { .. } )

I have no problem using notepad to edit the files (they're just .txt files really).. Depending on your windows setup, you might need to set a file assignment up first... hold shift, right click a .mit file, then select "Open with".. select Notepad from the list and make sure the 'always use this program to open this filetype' checkbox is selected.

Alternatively, go download the free 'Express' version of Visual Studio 2008 (or 2010 or whatever) and use that to manage your scripts. With a bit of setup (which i won't go into here) you then get the benefit of a project management window (allowing you to arrange all your different files nicely when your script projects starting gettin big) as well as a bit of syntax highlighting in the code. (Once you get used to it, no code looks right unless comments are in green).

Hope that helps.
Last edited by Mit on Tue Sep 04, 2012 3:48 pm, edited 1 time in total.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

and/or what xmakina said while i was busy writing my response :)

And yes.. we need lots more samples.. the full set of Civilisation scripts will be posted soonish and they contain an awful lot of useful stuff and techniques. I'll also extend the basic world installer so its a version of the Genesis world by default, which'll include some simple (and more complex) scripts to get you started
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok so let me try to get this right if i make a script that says something like this

Code: Select all

Event (newplayer)
{*say get out now
sleep(100)
*kick %player%}
that would say get out now to all first timers then kick them 10 secs later right??
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

close, but no cigar. You've mostly got the principles right, just need to get the formatting restrictions of the language..

1) The formatting of the parameters for the Event are incorrect. It should really look like this..

Code: Select all

Event( "NewPlayer", "" )
Events are expected to be defined with 2 parameters in quotes, separated by a comma, even though the second might not always be relevant.
That said, i suspect the current parser may well deal with

Code: Select all

Event(NewPlayer)

perfectly well. If it does, let me know and then you can ignore this 1) :]. If it doesnt work, let me know and i'll make it so.

2) The *say command broadcasts the message to everyone connected, not just to the player who triggered the script. (Which doesn't seem to be the thing you were after).

Code: Select all

*msg %PLAYER% get out now
is probably more appropriate.

3) You need to keep each separate 'script command' (which includes the { } stuff ) on a new line.

Soo..

Code: Select all

Event( "NewPlayer", "" )
{
  *msg %PLAYER% get out now
  Sleep(100)
  *kick %PLAYER%
}
would do what you were after, i think.
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok i got my first script to work now thanks
perfectly well. If it does, let me know and then you can ignore this 1) :]. If it doesnt work, let me know and i'll make it so.
it has to look like

Code: Select all

event ( "newplayer", "" )
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

something I've always wondered, mit.

In events such as "PlayerLogin", "NewPlayer" etc that seem to have a blank 2nd part, would it be possible to have that second part reference a billing id? Or can it already?
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

I dont really see the worth in making that part of those events, zar.. It complicates things (for the server and the script code) and I don't think the possible uses for it justifies that complication. (Feel free to tell me otherwise if you've got a specific requirement in mind). Of course, you can already do things in the existing NewPlayer event that are for a particular $gPlayerID, which I think is sufficient.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Nah, I can't think of any necessary uses
Was just curious about it is all.
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok haveing a osd problum now with script so i found a osd script to see if it was me or what so i used this script

Code: Select all

Event( "PlayerLogin" 0 ) 
   { 
    sleep(20) 
    osdcreate(OSDLIST,”Main”,”Hello World”) 
    osdadditem(OSDTEXT, ””, “How would you like to respond”) 
    osdadditem(OSDBUTTON, “Option1”, “Positively”) 
    osdadditem(OSDBUTTON, “Option2”, “Negatively”) 
    osdactivate() 
   } 

Event( “OSDSelect”, “Main:Option1” ) 
   { 
    osdcreate(OSDLIST,”Congrats”,”You responded positively”) 
    osdadditem(OSDEXITBUTTON, “Exit”, “Ok”) 
    osdactivate() 
   } 

Event( “OSDSELECT”, “Main:Option2” ) 
   { 
    osdcreate(OSDLIST,”Congrats”,”You responded negatively”) 
    osdadditem(OSDEXITBUTTON, “Exit”, “Ok”) 
    osdactivate() 
   }
it makes a osd popup but when hitting ither buttin it closes the osd and duse nuthing else tho it shuld make a new screen popup as well
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

That script looks ok at first glance to me.
The only thing that looks a bit odd is all the different styles of quotation marks that surround the OSDSelect.. (Though im not sure if thats just the forum being weird or if they're actually different characters).
I'll check this out later.
(And if necessary, adjust the parser so it recognises any type of quotes rather than just the plain " )
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

that seems to have fix it when i replaced all the " in it :) thanks
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

what is a OSDBULLET and how is it used??
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

thats sorta like OSDTEXT.. but with bullet the text is indented with a lil bullet-point symbol in front of it.
Fairly simple way of just adding a bit of formatting to your OSD. e.g.

Code: Select all

    osdcreate(OSDLIST,”Main”,”Hello World”) 
    osdadditem(OSDTEXT, ””, “Here is a list of shapes:”) 
    osdadditem(OSDBULLET, ””, “Square”) 
    osdadditem(OSDBULLET, ””, “Triangle”) 
    osdadditem(OSDBULLET, ””, “Dodecahedron”) 
    osdadditem(OSDBUTTON, “Ok”, “Kewl”) 
    osdactivate() 
(I don't use it much anymore.. all the civ stuff uses just text and images with OSDAddAt (rather than OSDAddItem) and positions all the UI manually - which is much more time consuming to write but gives more fine-grained control of where the text and images appear).
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok my problum is that my osd dont look right. the osd dont go down all the way
here is a image of what i mean

Image

and here is the code im useing

Code: Select all

Event( "AccessBuilding", "1" )
 {
  osdcreate(OSDLIST,"8","You see something shining on the grund next to a tree stump.")
  osdaddat(osdIMAGE, 0, 0, 590, 300, "", "http://i50.tinypic.com/m8l62u.jpg" )
  osdaddat(OSDIMAGE, 5, 5, 255, 290, "", "http://i49.tinypic.com/30rmv5i.jpg" )
  osdaddat(OSDBIGTEXT, 280, 10, 295, 145, "1.1", "Will you take a closer look to see what it is?")
  osdaddat(OSDBUTTON, 280, 240, 295, 20, "8a", "Yes")
  osdaddat(OSDBUTTON, 280, 265, 295, 20, "8b", "No")
  osdactivate() 
 }
it works just fine if i use the osdadditem but dus that when i use osdaddat
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

nvm morvis helped me figger it out :P
User avatar
MasterNiCron
Posts: 582
Joined: Wed Feb 17, 2010 10:57 pm
Location: Frost

Post by MasterNiCron »

ok a few things

(1) how can i make a building be able to be used only 1 time till game death.

(2) is it pasable to make it so after triggering a 1 time only building the next time u try it gives a diferant osd.

(3)is there a way to trans port someone to a sertan spot on map for triggering a sertan building. ie telaport them

(4) what type of building is the resorses on civ like the clay and copper and stuff?
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

>> how can i make a building be able to be used only 1 time till game death.

$gPlayerNumDeaths tells you how many times the player has died. When the player users the building, record that (in a playervar) and check it in the building script.. if it matches then the player hasn't died since they last used the building.

There's limitations in that.. you'd have to use up 1 player var for each instance of the building so it's only really practical if this building is a special/unique one, and not something that people can make themselves. (If you want to have lots of buildings around that act like that we'd need to do something different and its probably not going to be feasible soon.)

>> 2) is it pasable to make it so after triggering a 1 time only building the next time u try it gives a diferant osd.

heres a wee sample..

Code: Select all

// The player var used to control access to the unique building (separated out so you can change it easily)
$kPlayerVarForBuildingAccess = 32
// The building type number of the unique building 
$kUniqueBuildingType = 12

Event( "AccessBuilding", "$kUniqueBuildingType" )
{
    $nextValidAccess = $gPlayerVar[$kPlayerVarForBuildingAccess]
    if ( $gPlayerNumDeaths >= $nextValidAccess ) 
    {
        // Show OSD for the user who can access the building
       osdCreate( ...
             ...

       // Update the players var with the number of deaths he'll need to have before
       // he can access the building again. (You'd probably want to do this elsewhere, 
       // perhaps after they've pressed an OSD button, so people don't waste their one 
       // chance by closing the building window by accident)
       $gPlayerVar[$kPlayerVarForBuildingAccess] = $gPlayerNumDeaths + 1  
    }
    else
    {
        // Show OSD for user saying 'You've already used this building in this life'
       osdCreate( ...
             ...
    }
}
(3)is there a way to trans port someone to a sertan spot on map for triggering a sertan building. ie telaport them

you can use the *goto command to send the player to a named building (which could be an 'invisible' ornamental placed wherever you want em to go). I thought there was a command to set the player to a map X,Y, but there doesnt seem to be (unless i've missed it). Assuming there isnt one, i'll add to the to-do list.

>> (4) what type of building is the resorses on civ like the clay and copper and stuff?

All the 'buildings' on civ (except the houses and towns) are 'scripted' buildings. (That don't do anything except run script)
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Unless things have changed, *goto wont work as the script commands are done as if the owner is typing them. Thus a player activating a script with a *goto command in it would just send the world owner to that location.

*send would work though.
Locked