Page 2 of 3
Re: How to initiate Python files in AlcScript?
Posted: Tue Nov 23, 2010 5:07 am
by Egon
D'Lanor wrote:You have commented out the ptAttribResponder line. I highly doubt Python could accept a notification from a responder it does not know about.
????
As I understand
Code: Select all
respSound = ptAttribResponder(1, 'Resp: Play sound')
Is nothing more than retriving first parameter given to pymod in AlcScript and assignin it to global variable.
As You can see: I don't use respSound, and wrtie notyfication whenether OnNotify is being lanched, so commenting this line should not change anything, becouse it's only initiate variable which is not used (or am I wrong?).
Anyway, just to be sure: I uncomented it, redone pak file and got the same result.
Re: How to initiate Python files in AlcScript?
Posted: Tue Nov 23, 2010 5:37 am
by D'Lanor
As a general rule I just do what Cyan does and try not to deviate too much from that. I don't know why it does not work for you. It does for me.
You could try the export log file and see if everything "boiled down" (as it is called there) correctly.
Re: How to initiate Python files in AlcScript?
Posted: Fri Nov 26, 2010 2:10 pm
by D'Lanor
I suddenly realize why your notification fails. In order for this to work the responder should be started through Python! *slaps head*
Re: How to initiate Python files in AlcScript?
Posted: Sat Nov 27, 2010 12:11 am
by Egon
D'Lanor wrote:I suddenly realize why your notification fails. In order for this to work the responder should be started through Python! *slaps head*

Re: How to initiate Python files in AlcScript?
Posted: Sat Nov 27, 2010 2:23 am
by D'Lanor
Sorry, I thought that was obvious. Based on the previous scripts it means:
- AlcScript Show Spoiler
[code]RegisterKI:
logic:
modifiers:
- name: RegisterKI
cursor: poised
flags:
- localelement
activators:
- type: objectinvolume
remote: nexusLBReg
triggers:
- any
conditions:
- type: activator
activators:
- type: picking
- type: objectinbox
satisfied: true
actions:
- type: pythonfile
ref: :NexusStation
actions:
- type: pythonfile
name: NexusStation
pythonfile:
file: NexusStation
params:
- type: activator
ref: logicmod:RegisterKI
- type: responder
ref: :insertKiResponder
- type: responder
name: insertKiResponder
responder:
states:
- cmds:
- type: oneshotmsg
params:
receivers:
- oneshotmod:InsertKIHandOneShot
callbacks:
- marker: HandIn
receiver: respondermod:insertKiResponder
user: 0
waiton: -1
- type: soundmsg
params:
receivers:
- 0011:InsertKIEmitter
callbacks:
- type: eventcallbackmsg
params:
receivers:
- respondermod:insertKiResponder
user: 1
event: 1
cmds:
- addcallbacks
- play
waiton: 0
- type: notifymsg
params:
receivers:
- pyfilemod:NexusStation
waiton: 1
- type: oneshotmsg
params:
receivers:
- oneshotmod:InsertKIHandOneShot
callbacks:
- marker: HandIn
receiver: respondermod:insertKiResponder
user: 2
waiton: -1
- type: soundmsg
params:
receivers:
- 0011:InsertKIEmitter
cmds:
- play
- setvolume
volume: 0.8
waiton: 2
nextstate: 0
ncallbacks: 3
waittocmd:
- key: 0
msg: 0
- key: 1
msg: 1
- key: 2
msg: 3
curstate: 0
flags:
- detecttrigger
[/code]
- Python Show Spoiler
[code]actKI = ptAttribActivator(1, 'Act: Insert KI')
respKI = ptAttribResponder(2, 'Resp: Insert KI', netForce=1)
avatar = None
#skipping some stuff here
def OnNotify(self, state, id, events):
global avatar
if (not PtWasLocallyNotified(self.key)):
return
if ((id == actKI.id) and state):
avatar = PtFindAvatar(events)
respKI.run(self.key, events=events)
elif (id == respKI.id):
print ('responder %d finished' % id)
if (avatar == PtGetLocalAvatar()):
PtSendKIMessage(kKILocalChatStatusMsg, "OnNotify")
[/code]
Edit: multiplayer compatible Python code
Re: How to initiate Python files in AlcScript?
Posted: Sat Nov 27, 2010 4:12 am
by Egon
D'Lanor wrote:Sorry, I thought that was obvious.
Actually I did undesrtood it. Just didn't know how to write that in AlcScript/Python
Anyway, I try to test it ASAP.
Re: How to initiate Python files in AlcScript?
Posted: Sat Nov 27, 2010 1:13 pm
by Egon
After testing:
Good news: OnNotify started to live

Bad news: i'ts styll not working.
When I click my button in game "id" passed to "OnNotify" is "-1", but the "actKI.id" is equal to "1".
I tryed to launch:
Code: Select all
avatar = PtFindAvatar(events)
respKI.run(self.key, events=events)
anyway (despite "id != actKI.id"), but nothing happends (after "respKI.run" script just moving on).
P.S.
Control question: since avatar is declared inside OnNotify as "global avatar" shouldn't actKI and respKI be also?
Re: How to initiate Python files in AlcScript?
Posted: Sun Nov 28, 2010 5:30 pm
by D'Lanor
Egon wrote:
When I click my button in game "id" passed to "OnNotify" is "-1", but the "actKI.id" is equal to "1".
I don't know where that -1 id is coming from but it cannot be a parameter from the pythonfile mod. PyPRP enumerates pythonfile mod parameters in the order they appear in the Alcscript. For the script I posted the activator is written to the prp file with id 1 and the responder with id 2. In Python you must capture the activator and the responder with the same ids. These numbers are not arbitrary. They should always match the corresponding ids within the prp file.
Somehow I don't think you used my actual script (again) so I won't try to troubleshoot this.
Egon wrote:P.S.
Control question: since avatar is declared inside OnNotify as "global avatar" shouldn't actKI and respKI be also?
No. The global statement should be declared when a function changes a global variable. actKI and respKI never change since they are not variables but constants.
Re: How to initiate Python files in AlcScript?
Posted: Wed Dec 01, 2010 10:14 am
by Egon
D'Lanor wrote:Somehow I don't think you used my actual script (again) so I won't try to troubleshoot this.
Well yes, and no

Of course that every time, at first, I tried Your code exactly as You have written it.
But like I sad: something always was wrong.
So I was tweeking, and testing (tweekeing, and testing, tweekeing, and testing etc.) Your code to:
a) learn priciples behind it
b) find out what I was doing wrong.
Anyway I find out what was wrong. In this code:
- AlcScript Show Spoiler
[code]RegisterKI:
logic:
modifiers:
- name: RegisterKI
cursor: poised
flags:
- localelement
activators:
- type: objectinvolume
remote: nexusLBReg
triggers:
- any
conditions:
- type: activator
activators:
- type: picking
- type: objectinbox
satisfied: true
actions:
- type: pythonfile
ref: :NexusStation
actions:
- type: pythonfile
name: NexusStation
pythonfile:
file: NexusStation
params:
- type: activator
ref: logicmod:RegisterKI
- type: responder
ref: :insertKiResponder
- type: responder
name: insertKiResponder
responder:
states:
- cmds:
- type: oneshotmsg
params:
receivers:
- oneshotmod:InsertKIHandOneShot
callbacks:
- marker: HandIn
receiver: respondermod:insertKiResponder
user: 0
waiton: -1
- type: soundmsg
params:
receivers:
- 0011:InsertKIEmitter
callbacks:
- type: eventcallbackmsg
params:
receivers:
- respondermod:insertKiResponder
user: 1
event: 1
cmds:
- addcallbacks
- play
waiton: 0
- type: notifymsg
params:
receivers:
- pyfilemod:NexusStation
waiton: 1
- type: oneshotmsg
params:
receivers:
- oneshotmod:InsertKIHandOneShot
callbacks:
- marker: HandIn
receiver: respondermod:insertKiResponder
user: 2
waiton: -1
- type: soundmsg
params:
receivers:
- 0011:InsertKIEmitter
cmds:
- play
- setvolume
volume: 0.8
waiton: 2
nextstate: 0
ncallbacks: 3
waittocmd:
- key: 0
msg: 0
- key: 1
msg: 1
- key: 2
msg: 3
curstate: 0
flags:
- detecttrigger
[/code]
In this
- section Show Spoiler
[code]actions:
- type: pythonfile
name: NexusStation
pythonfile:
file: NexusStation
params:
- type: activator
ref: logicmod:RegisterKI
- type: responder
ref: :insertKiResponder[/code]
It should be "parameters:" insetad of "params:"
Re: How to initiate Python files in AlcScript?
Posted: Wed Dec 01, 2010 10:33 am
by D'Lanor
Oops, I copied that from your post #5 and never noticed the error.

No wonder everything after that was broken. Anyway, glad it is solved now.