Privateer GG talking heads
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
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.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
I need some clarification on the innards of this bit here:
Reason being, this is the code that passes the sprite information and calls the Speak function for the text and audio.
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)
Last edited by Herr_Koos on Fri Dec 21, 2012 5:08 pm, edited 1 time in total.
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
Base.Python creates a hot zone that triggers a python script when clicked/activated.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Is it documented anywhere?
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
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.
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.
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
Nope. We really need some contributions here....Herr_Koos wrote:Is it documented anywhere?
Base.RunScript would let you run another script that changes the sprite.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.
Did you manage to run a simple script? From there to changing the sprite is just a small step.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.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
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.
If you could talk me through the GUI.py example, I will try and take it from there.
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
Imagine I have:
That will print "STOPTALKING!" on the console 10 seconds after it's run.
Now, suppose I have:
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:
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):
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.
Code: Select all
Base.RunScript(someroom,"STOPTALKING","#\nprint 'STOPTALKING!'",10.0)
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)
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)
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!'
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Great, that gives me something solid to work on. Much appreciated.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
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.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Another question: What does this bit here do?
% { 'someroom' : someroom }
% { 'someroom' : someroom }
Re: Privateer GG talking heads
That is the funky python string formatting: http://docs.python.org/2/library/stdtyp ... formatting
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Got it, thanks. The pieces are coming together...log0 wrote:That is the funky python string formatting: http://docs.python.org/2/library/stdtyp ... formatting
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
No joy. I followed the example to the letter. Code looks as follows:
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?
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)
#
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?
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
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.
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.
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
If you want newlines inside strings without escaping them, you have to use triple-quotes: """blabla"""Herr_Koos wrote:SyntaxError: EOL while scanning single-quoted string
You probably used "\n" inside a string, that produces a newline. If you want a string inside a string, do double backslash: " ' \\n' "
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Well, I just copied the syntax in your example. Can you take a look at the code I posted?
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
I may have made the mistake, I didn't check it. Just an example.Herr_Koos wrote:Well, I just copied the syntax in your example. Can you take a look at the code I posted?
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.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Cool, hope the exams went well. Yes please, the last section of code I posted in which I tried your example.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
Tried the \\n and it appears to work, but the script repeats every specified time interval instead of only running once after the click.
-
- Trader
- Posts: 31
- Joined: Wed Dec 12, 2012 10:43 am
Re: Privateer GG talking heads
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
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:
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...
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...
}
}
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
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
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.
Would be great if someone could integrate it into the wiki, no idea where to put it.
-
- Elite
- Posts: 7243
- Joined: Mon Apr 18, 2005 2:40 pm
- Location: LS87, Buenos Aires, República Argentina
Re: Privateer GG talking heads
The tricky thing is... where do we put that so that it will stay in sync?