How do I switch PCs?
I did this successfully a year ago, but it wasr tricky. I lost my old code with my computer.
It looks to me that I’ve got the second Actor object trying to become the PC, by using gameMain.initialPlayerChar = self, but somehow gamemain.initialPlayerChar isn’t resetting. Thoughts?
[code]… control code …
DefineTAction(SwitchTo)
;
VerbRule(SwitchTo)
(‘switch’ ‘to’ | ‘become’) singleDobj
: SwitchToAction
verbPhrase = ‘switch/switching (to who)’
;
modify Actor
dobjFor(SwitchTo)
{
action()
{
gameMain.initialPlayerChar = self;
"Did it work? Are you <<self.name>>? ";
}
}
;
… room defs snipped …
me: Actor ‘fellow’ ‘fellow’
location = entryway
;
me2: Actor ‘guy’ ‘guy’
location = entryway
;
gameMain: GameMainDef
initialPlayerChar = me;[/code]
… what happens …
The guy is standing here.
x guy
You see nothing unusual about the guy.
x fellow
You look the same as usual.
switch to guy
Did it work? Are you guy?
x fellow
You look the same as usual.
x guy
You see nothing unusual about the guy.
initialPlayerChar is only used to set gPlayerChar during init. (gPlayer is a macro for libGlobal.playerChar.)
Does it work if you do this instead?
modify Actor
dobjFor(SwitchTo) {
action() {
gPlayerChar = self;
"Did it work? Are you <<self.name>>? ";
}
}
;
Thanks, Ben! That did it.
Conrad.
…
x guy
You see nothing unusual about the guy.
switch to guy
Did it work? Are you guy?
x fellow
You see nothing unusual about the fellow.
x guy
You look the same as usual.
I’m posting the basic, working code for anyone down the line who wants to do this.
This is no-frills code, which allows the player to switch into any character of the Actor class. It does not address the case where the player tries to switch into an object – you get the default “You can’t do that.” – and does not consider that you might want some Actors switchable-to, and some not.
[code] DefineTAction(SwitchTo)
;
VerbRule(SwitchTo)
(‘switch’ ‘to’ | ‘become’) singleDobj
: SwitchToAction
verbPhrase = ‘switch/switching (to who)’
;
modify Actor
dobjFor(SwitchTo)
{
action()
{
"Switching from <<gPlayerChar.name>> to <<self.name>>… ";
gPlayerChar = self;
"You are now <<gPlayerChar.name>>. ";
}
}
;[/code]