Page 2 of 3

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 8:22 am
by klauss
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 11:18 am
by Herr_Koos
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 3:25 pm
by klauss
Base.Python creates a hot zone that triggers a python script when clicked/activated.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 3:55 pm
by Herr_Koos
Is it documented anywhere?

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 4:46 pm
by Herr_Koos
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 5:38 pm
by klauss
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 5:48 pm
by Herr_Koos
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 6:09 pm
by klauss
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.

Re: Privateer GG talking heads

Posted: Wed Dec 19, 2012 11:08 pm
by Herr_Koos
Great, that gives me something solid to work on. Much appreciated.

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 11:30 am
by Herr_Koos
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.

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 12:38 pm
by Herr_Koos
Another question: What does this bit here do?

% { 'someroom' : someroom }

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 1:48 pm
by log0
That is the funky python string formatting: http://docs.python.org/2/library/stdtyp ... formatting

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 3:06 pm
by Herr_Koos
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...

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 4:56 pm
by Herr_Koos
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?

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 5:04 pm
by Herr_Koos
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.

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 6:51 pm
by klauss
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' "

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 7:08 pm
by Herr_Koos
Well, I just copied the syntax in your example. Can you take a look at the code I posted?

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 7:43 pm
by klauss
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.

Re: Privateer GG talking heads

Posted: Fri Dec 21, 2012 7:51 pm
by Herr_Koos
Cool, hope the exams went well. :) Yes please, the last section of code I posted in which I tried your example.

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 12:22 pm
by Herr_Koos
Tried the \\n and it appears to work, but the script repeats every specified time interval instead of only running once after the click.

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 12:41 pm
by Herr_Koos
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...

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 3:52 pm
by log0
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...

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 4:29 pm
by log0
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)

...

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 6:46 pm
by log0
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.

Re: Privateer GG talking heads

Posted: Sat Dec 22, 2012 6:54 pm
by klauss
The tricky thing is... where do we put that so that it will stay in sync?