Privateer GG talking heads

Forum for discussing various mods for the VS-engine based upon Privateer. (Please play nice now, and extinguish all flaming materials.
Sincerely, The Management)

Re: Privateer GG talking heads

Postby klauss » Wed Dec 19, 2012 1:22 am

Only at engine launch time, AFAIK. So yes, you can print at any time, and when you exit VS you have everything in stderr/out. Needless to say, it can become quite big.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Share On:

Share on Facebook Facebook Share on Twitter Twitter Share on Digg Digg

Re: Privateer GG talking heads

Postby Herr_Koos » Wed Dec 19, 2012 4:18 am

I need some clarification on the innards of this bit here:

Code: Select all
Base.Python (room0, 'talk', 0.5875, -0.373333, 0.285, 0.626667,'Talk to the Bartender',script+"import bartender\nbartender.Speak (bartender.GetBartenderText("+repr(bartext)+"))\n",0)


Reason being, this is the code that passes the sprite information and calls the Speak function for the text and audio.
Last edited by Herr_Koos on Fri Dec 21, 2012 10:08 am, edited 1 time in total.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby klauss » Wed Dec 19, 2012 8:25 am

Base.Python creates a hot zone that triggers a python script when clicked/activated.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Re: Privateer GG talking heads

Postby Herr_Koos » Wed Dec 19, 2012 8:55 am

Is it documented anywhere?
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Wed Dec 19, 2012 9:46 am

Seems that the current behaviour makes it very difficult to swap out one sprite for another. The script refers to a particular spr file, which is then inserted in Base.Python and thus displayed when you click on the character to start the conversation. No way to change the sprite being used until Base.Python is invoked again, hence you are stuck with one sprite the whole time.

As for the earlier suggestion to use Base.RunScript, I cannot really make anything of it. The example in GUI.py doesn't make sense to me yet.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby klauss » Wed Dec 19, 2012 10:38 am

Herr_Koos wrote:Is it documented anywhere?


Nope. We really need some contributions here....

Herr_Koos wrote:Seems that the current behaviour makes it very difficult to swap out one sprite for another. The script refers to a particular spr file, which is then inserted in Base.Python and thus displayed when you click on the character to start the conversation. No way to change the sprite being used until Base.Python is invoked again, hence you are stuck with one sprite the whole time.

Base.RunScript would let you run another script that changes the sprite.

Herr_Koos wrote:As for the earlier suggestion to use Base.RunScript, I cannot really make anything of it. The example in GUI.py doesn't make sense to me yet.


Did you manage to run a simple script? From there to changing the sprite is just a small step.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Re: Privateer GG talking heads

Postby Herr_Koos » Wed Dec 19, 2012 10:48 am

Not yet; I've been trying to get clued up on some basic Python syntax. Im quite a bit more knowledgable than a few days ago, but it's slow going.

If you could talk me through the GUI.py example, I will try and take it from there.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby klauss » Wed Dec 19, 2012 11:09 am

Imagine I have:

Code: Select all
Base.RunScript(someroom,"STOPTALKING","#\nprint 'STOPTALKING!'",10.0)


That will print "STOPTALKING!" on the console 10 seconds after it's run.

Now, suppose I have:

Code: Select all
someroom = ...
stoptalkingscript = """#
import Base
print "STARTTALKING"
Base.RunScript(%(someroom)d,"STOPTALKING","#\nprint 'STOPTALKING!'",10.0)
""" % { 'someroom' : someroom }
Base.Python(someroom, "STARTALKING",x,y,w,h,"talk to me",stoptalkingscript,True)


That will create a hot zone in x,y with size w,h, and a tooltip "talk to me" which, when acted upon, will print "STARTTALKING", wait 10 seconds, and print "STOPTALKING!".

The "#" at the beginning of the script is necessary to avoid VS trying to compile it as a module - ie, to let it know it's an inline script to run.

I really don't remember all the parameters in Base.Python, I'd have to read the source to find out.

When the hot zone is clicked, the script that will run is:

Code: Select all
import Base
print "STARTTALKING"
Base.RunScript(%(someroom)d,"STOPTALKING","#\nprint 'STOPTALKING!'",10.0)


That will import Base (as I said, those scripts are run on an empty context, so you can't access variables from outside except modules, if you import them). GUI.py has a message dispatch system exactly because of this limitation, callback scripts use it to send stuff back to the calling code.

Anyway, the code will be run, and a delayed script will be added to the base. So the game will continue to work normally for those 10 seconds, at which time it will run (if it's still on the base):

Code: Select all
print 'STOPTALKING!'


Of course, you can do something more interesting than a mere print. Again, you have to import Base, or whichever module you intend to use.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Re: Privateer GG talking heads

Postby Herr_Koos » Wed Dec 19, 2012 4:08 pm

Great, that gives me something solid to work on. Much appreciated.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 4:30 am

Playing with the scripts now, will let you know how that goes. One more quick question: Is there a built in function to get the current time? say I wanted to display: "Sound is now playing"+time index, and "Sound has now stopped"+time index.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 5:38 am

Another question: What does this bit here do?

% { 'someroom' : someroom }
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby log0 » Fri Dec 21, 2012 6:48 am

That is the funky python string formatting: http://docs.python.org/2/library/stdtyp ... formatting
log0
 

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 8:06 am

log0 wrote:That is the funky python string formatting: http://docs.python.org/2/library/stdtyp ... formatting


Got it, thanks. The pieces are coming together...
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 9:56 am

No joy. I followed the example to the letter. Code looks as follows:

Code: Select all
talkingscript = """#\nimport Base\nprint "Talkingscript is now running"\nBase.RunScript(%(room0)d,"TALK","#\nprint 'The embedded script is now running'",3.0)\n"""
% { 'room0' : room0 }
Base.Python (room0, 'talk', 0.5875, -0.373333, 0.285, 0.626667,'Talk to the Bartender',talkingscript,True)
 

This means the script to be executed three seconds after clicking the bartender should be:
#
import Base
print "Talkingscript is now running"
Base.RunScript(16,"TALK","#
print 'The embedded script is now running'",3.0)

room0=Bar=16 in this case.

But upon execution, in stderr I get the following after every click:
File "<string>", line 4
Base.RunScript(16,"TALK","#
^
SyntaxError: EOL while scanning single-quoted string

Clearly it doesn't like the \n in the embedded script, so I removed it.

Next attempt: I click on the bartender, and lo and behold, no error reported. However, in stdout, I get:
Talkingscript is now running (this is good)
And then after clicking on the bartender:
Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... Running python script... and so on and so forth.

A new "Running python script" entry is added every 3 seconds, apparently as per the interval I specified (isn't it supposed to only execute once?), but the embedded message is never displayed.

I feel I must have done something wrong. Any insights?
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 10:04 am

Another thing:

talkingscript = """#\nimport Base\nprint "Talkingscript is now running"\nBase.RunScript(%(room0)d,"TALK","#\nprint 'The embedded script is now running'",3.0)\n"""
% { 'room0' : room0 }
Base.Python (room0, ''talk', 0.5875, -0.373333, 0.285, 0.626667,'Talk to the Bartender',talkingscript,True)

The arguments I highlighted appear to me to be completely arbitrary; I have no idea what they do.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby klauss » Fri Dec 21, 2012 11:51 am

Herr_Koos wrote:SyntaxError: EOL while scanning single-quoted string

If you want newlines inside strings without escaping them, you have to use triple-quotes: """blabla"""

You probably used "\n" inside a string, that produces a newline. If you want a string inside a string, do double backslash: " ' \\n' "
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 12:08 pm

Well, I just copied the syntax in your example. Can you take a look at the code I posted?
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby klauss » Fri Dec 21, 2012 12:43 pm

Herr_Koos wrote:Well, I just copied the syntax in your example. Can you take a look at the code I posted?

I may have made the mistake, I didn't check it. Just an example.

Which code do you mean? (there are tons of code). I'm assuming the one you posted with the syntax error.

Exams are over so I will probably have some time to test it once I get home. In the meanwhile, try escaping as I said above.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Re: Privateer GG talking heads

Postby Herr_Koos » Fri Dec 21, 2012 12:51 pm

Cool, hope the exams went well. :) Yes please, the last section of code I posted in which I tried your example.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Sat Dec 22, 2012 5:22 am

Tried the \\n and it appears to work, but the script repeats every specified time interval instead of only running once after the click.
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby Herr_Koos » Sat Dec 22, 2012 5:41 am

I'm also finding that trying to replace a simple print command with anything else (such as running another script, for instance) is proving to be a major headache...
Herr_Koos
Trader
Trader
 
Posts: 31
Topics: 1
Joined: Wed Dec 12, 2012 3:43 am

Re: Privateer GG talking heads

Postby log0 » Sat Dec 22, 2012 8:52 am

Please note that I have zero experience with vs python.

From looking at the c++ code:

RunScript( int room, std::string ind, std::string pythonfile, float time ) will create a BaseInterface::Room::BasePython object.

This object will execute the following call:
Code: Select all
void BaseInterface::Room::BasePython::Draw( BaseInterface *base )
{
    timeleft += GetElapsedTime()/getTimeCompression();
    if (timeleft >= maxtime) {
        timeleft = 0;
        VSFileSystem::vs_dprintf( 2, "Running python script... " );
        RunPython( this->pythonfile.c_str() );
        return;         //do not do ANYTHING with 'this' after the previous statement...
    }
}

Means script will be repeated after maxtime as you've noticed.

To stop the script you have to call Base.EraseObject(ind) . In your case it would be Base.EraseObject("TALK").

This stuff really needs to be documented...
log0
 

Re: Privateer GG talking heads

Postby log0 » Sat Dec 22, 2012 9:29 am

There are 48 Base calls. Will see if I am bored enough to complete them, should go into wiki I guess....
Code: Select all
# Add a room with displayed name = text
# Return room id (int)
Base.Room(string text)

# Set current room
Base.SetCurRoom(int id)

# Get active room
# Return room id (int)
Base.GetCurRoom()

# Get number of rooms (int)
# Return -1 if base not valid
Base.GetNumRoom()

# Same as Base.GetNumRoom()
Base.HasObject()

# Add a computer to a room
# room:         room id
# index:      computer index
# x, y, w, h:    link area
# text:         link area text
# modes:       Cargo, Upgrade, ShipDealer, Missions, News, Info, LoadSave, Network
Base.Comp(int room, string index, float x, float y, float w, float h, string text, string modes)

# Add a computer to a room
# room:         room id
# index:      computer index
# pythonfile:   link area script to be executed on click
# x, y, w, h:    link area
# text:         link area text
# modes:       Cargo, Upgrade, ShipDealer, Missions, News, Info, LoadSave, Network
Base.CompPython(int room, string index, string pythonfile, float x, float y, float w, float h, string text, string modes)

...
log0
 

Re: Privateer GG talking heads

Postby log0 » Sat Dec 22, 2012 11:46 am

I've attached the vs python Base API. It is almost complete, one call missing( Base.Python ).

Would be great if someone could integrate it into the wiki, no idea where to put it.
log0
 

Re: Privateer GG talking heads

Postby klauss » Sat Dec 22, 2012 11:54 am

The tricky thing is... where do we put that so that it will stay in sync?
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina


PreviousNext

Return to Privateer Universe

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

cron