Multiple Character Game Object switching

Raftronaut

Member
Hoping to get some advice as to how I can achieve character switching in the adventure module.

I have a specific need to have 4 switchable characters in my adventure game. I have my initial player set up and the remaining 3 player characters set up in the monster banks ready to go . However, I am entirely uncertain how I would go about actually switching the player object Persistent tag from one character to the other.

Obviously this would require some custom ASM code, but hoping I could accomplish this by using the select button to change character states.

Could anyone here recommend where I should get started in order to solve this?

I am still a bit foggy regarding the scripts as well, once some custom ASM code like this is written it can be imported as a module script
Correct? I would assume this would be helpful to others that would require separate character states for their designs as well, I.E. charcter powerups, or costume changes etc...


This is my first post to the forum, please let me know if I am directing my questions to the correct area!!!!
:roll:
 

Knietfeld

Member
I just came across your post last night. It's been a while since you posted, did you figure anything out yet?
I tried to create a complete solution for you but I barely got started on it when my baby woke up and that was the end of that. I have some ideas though, and hopefully can work on it more tonight. I was able to replace my player character with another object but I couldn't make the new one move yet. You specifically mentioned the persistent tag and that, which is stored in the ObjectFlags variable, should be pretty simple to copy over into the new object's variable if we need to.
Anyway, I'm mostly just letting you know someone is trying to figure this out for you. I wish I could have done more already. It seems like a fun problem to solve and I've been trying to figure out a similar problem for my game. I've been coding in asm for a couple years now, but I'm still learning how nesmaker's code is all laid out and where I can plug stuff in to make it do what I want.

This is also my first post to this forum... My first post to any forum, I think. I don't know if it's in the right spot, but it makes sense to me.
 

Nz17

New member
I would also like to switch among multiple playable characters a la The Lost Vikings. Any help is appreciated!
 

Raftronaut

Member
Knietfeld said:
I just came across your post last night. It's been a while since you posted, did you figure anything out yet?
I tried to create a complete solution for you but I barely got started on it when my baby woke up and that was the end of that. I have some ideas though, and hopefully can work on it more tonight. I was able to replace my player character with another object but I couldn't make the new one move yet. You specifically mentioned the persistent tag and that, which is stored in the ObjectFlags variable, should be pretty simple to copy over into the new object's variable if we need to.
Anyway, I'm mostly just letting you know someone is trying to figure this out for you. I wish I could have done more already. It seems like a fun problem to solve and I've been trying to figure out a similar problem for my game. I've been coding in asm for a couple years now, but I'm still learning how nesmaker's code is all laid out and where I can plug stuff in to make it do what I want.

This is also my first post to this forum... My first post to any forum, I think. I don't know if it's in the right spot, but it makes sense to me.


HI Knietfeld! I appreciate your response and interest! I have not solved the problem as of yet. Although I did get some clues from JOE today on the facebook forum earlier today. According to him, the solution to having multiple character states is as follows:

1) Understand how to create and destroy objects...like when the player turns into the "death" version of the player.
2) Understand how the variable player1_object works.

this is what i'll be focusing on tinkering with on my next nesmaker session, hopefully I will learn some things with trial and error. Once I come up with some answers I will be sure to post them here as I am sure others will find it helpful. This could be a very good way to handle player upgrades, vehicles, costume changes, power ups ETC...
 

Knietfeld

Member
Yep, those are exactly the things I was playing with. I used the handle player death script as a base and switched some things around so the player character is destroyed first then the new object is created. Since the createobject macro just searches for the first available spot to place the new object, it places the new object in the player object's recently vacated place. This lets you control the new objects left and right movement (I've been using the platformer module, in the adventure module it may let you control other directions) but the action states don't change. So I was trying to figure out more about all the parts of code that affect player1_object, and what I can do to control or change it. Anyway, good luck! I'll keep toying with it too and let you know what I figure out.
 

Raftronaut

Member
Could you post the script you're working with?

I found the handle player death script, but I am confused to a few things, wondering where my variables should be
 

Knietfeld

Member
I started to work on other parts of my game and haven't come back to this in a while. but this is what I was dealing with. any comment that start with ;kn, are things I wrote either to help you understand or to help me understand as I was working with it. I set this chunk of code as an input scrip and told it to run when I released the select button so I could test in in my game. I can't remember if I was messing with it and made it stop working the last time I played with it and my game isn't in a state where I can easily try again, but Here's what I was working with

Code:
TXA
    STA tempx
    TYA 
    STA tempy
    
    ;;;;;;;;;;;;;;;;;;;
    LDX player1_object 
    LDA Object_x_hi,x ;kn copy player x location
    STA temp
    LDA Object_y_hi,x ;kn copy player y location
    STA temp1
    lda Object_type,x 
    sta temp2 
    
    
    LDX player1_object
    DeactivateCurrentObject ;kn, if you compare these to handleplayerDeath, 
							;   you'll see that they did it the opposite way in that script because they didn't
							;	want the death animation to take the spot of player1_object, we do, so in this script 
							;	these two macros are refered to this way, 
							;	first destroy the old object then replace it with the new one.
    CreateObject temp, temp1, #$0a, #$0 ;use those to create new object in place of player character
			;		^	^		^	^
;kn-I pasted in what these numbers mean from macros.asm below. 
	; I have #$0a in arg2 because the object sprites take up spaces 00-0f and the sprite I was trying to replace 
	; my player with was at the Effect 2 spot in my Game Objects menu in NesMaker. Counting down from the top 
	; (with my main player sprite being 00), in Hex makes Effect 2 #$0a.
	; If you want to replace player with an object in the Monsters table (say, #$11 for example) instead of a Game Object, the sprite
	; will change if you go in a room that has different monsters assigned to it.
	
;CreateObject arg0, arg1, arg2, arg3  ;; arg 3 = action step?
	;arg0 x value
    ;arg1 y value
    ;arg2 object type 
    ;arg3 action step - great for creating a 'spawning' effect that is non-zero
                        ;; or even for creating projectiles that may behave differently, where
                        ;; a single projectile could have 8 action types that are different, and 
                        ;; could load that particular action step, which could show a unique animation
                        ;; with specialized behaviors?  Just a thought.
    
    ;; need to do this redundantly, otherwise, the death object will be in same slot as player
    ;stx player1_object
    ; lda temp2 
     ; sta Object_type,x
    ; CreateObject temp, temp1, #$00, #$0
    ;;;;;;;;;;;;;;;;;;;
    
    
    ;LDA #$0a
    ;STA player1_object
    
    LDX tempx
    LDY tempy

Another tip I can give you, that I discovered in messing with all this code, is that in Nesmaker/Game Engine Data there is a file called demo.txt. this file is created every time you export your game and is basically all the code for your game in one place. if you don't know what a variable is doing, or how it is used throughout the whole game, you can open that text file and hit ctrl+F and search for that variable. if you find a script that looks like it is doing something you want to change, just go to the top of that particular script and the address for it is in the "include" line. then you can easily find that script, open that script in Notepad++ or whatever editor you use, and you can cut and paste from it or edit it.

Good Luck. Sorry I haven't got more to show you yet. Hopefully what I said made a little sense.
 

Raftronaut

Member
I had actually given up on this and moved onto other assets I'd been working on. NM 4.1 gave me a host of new things to work on however I am very much still interested in how this accomplished. Actually hoping that with 4.1 some module will be created to shed some light on how this is properly achieved....
 
Into surenif you are still working on this code , but I'm working a code similar to this and working on screen triggers new player , from what I cam see this is what you have going on as well. I going to grab your code and see if I cam adapt bla d it with mine to get it working and I will let you know
 
Wondering if you are still working on this code , but I'm working a code similar to this and working on screen triggers new player , from what I cam see this is what you have going on as well. I going to grab your code and see if I cam adapt bla d it with mine to get it working and I will let you know
 

mouse spirit

Well-known member
I believe i have figured this one out, as far as an easy object player switch.I used an input script used with the Select Button,a user constant, and an object. Press Select to switch!

This should work in the platformer module with NESmaker 4.1.5.

1. Create a user constant in project settings.Name it
whatever you like but make it's value equal to your new player objects postion in the line up in Game Objects.(mine is object 15, so i made my value 15)

2. Make a new asm script.Name it what you like, it will be an input script so place it in the appropriate folder for when we import it.
Code:
;changing characters
TXA
STA tempx
TYA
STA tempy

LDX player1_object
LDA Object_x_hi,x
STA temp
LDA Object_y_hi,x
STA temp1

DeactivateCurrentObject

CreateObject temp, temp1 #(your user constant), #$00, currentNametable

LDX tempx
LDY tempy

3. Save that script and import as an input script and assign it to the Select Button.

Hope it works for you as it does for me. It should normally unless i made a typo in the code on here.
 
Top Bottom