SOLVED: change main characters name on the fly depending on character chosen

Started by barefoot, Tue 19/07/2011 12:02:17

Previous topic - Next topic

barefoot

Hi

I have created a global variable: cars  int

There are 3 cars available: red, blue and green.

The player picks a car (clicks on a car image) to play game as.

On the next screen the picked car is now the main player: either red, blue or green.

So far so good..

I want to rename any car picked as the main player.

IE credcar becomes ccar, cbluecar becomes ccar or cgreencar becomes ccar.

I was thinking along the lines:

Code: ags

}
if(player==cbluecar) {
player.Name=ccar

}
else if(player==credcar) {
player.Name=ccar

}


Etc..  This would apply to any car picked. This would mean i can just script for ccar.

Code: ags

SetAsPlayerName


I know my code is not correctly put but gives an idea of what i am trying to achieve.

I'm toying with a few ideas but a gentle hand at this point would certainly help.

cheers

barefoot







I May Not Be Perfect but I Have A Big Heart ..

Matti

Quote from: barefoot on Tue 19/07/2011 12:02:17
Etc..  This would apply to any car picked. This would mean i can just script for ccar.

You could just script using player. Or store the number of the currently used car character and use character[car]. Or you could change the way the name of the cars is displayed before the player chooses one.

I was wondering why you'd want to change the script-name of a character. I don't think that's possible.

barefoot

Hi Matti

well, if you have 3 cars to choose from you only really want to script for 1.

by changing any cars name to the same name will naturally mean that if you want that player, whatever car they chose, to do something you only need to call 1 name.

eg

car.move
car.walk
car.Say

etc etc

Of course it could be any name you choose.

All I need to do is change playername.

This is the part I am trying to work out.

cheers

barefoot


FOOTNOTE.. Maybe i could set 1 main player and change all its views to compensate for which ever colour car is chosen. Food for thought?



I May Not Be Perfect but I Have A Big Heart ..

Matti

As I said, you could just use

player.Move
player.Walk
player.Say

If one of the cars is set as the player character, the views should already be correct, shouldn't they?

Khris

Welcome to the wonderful world of pointers :)

If you don't for instance have a player selection screen where the three cars are like randomly driving around the screen or something there's no need to create three AGS characters in the first place. All you have to let the player choose is appearance i.e. the NormalView and SpeechView.

So let's say you have created a character (Script name: cCar) and it is set as the player character.
All you do is:

Code: ags
function bRedCar_OnClick(...) {
  // player chose the red car:
  player.ChangeView(2);
  player.SpeechView = 3;
  ...
}


Now let's assume that you actually have three characters because like I said, they drive into the screen or whatever. They already have their views set up correctly, so what's left to do is if the player clicks the red car, call:

Code: ags
  cRedCar.SetAsPlayer();


Now the pointer player will point to cRedCar, so all you do is use commands like in Matti's post.

There's a final consideration to be made here: if you actually had a guy as player character already and the car is his sidekick or something, what you do is define a global pointer called "car":

Code: ags
  // header
  import Character*car;

  // top of global.asc
  Character*car;
  export car;


Now all you do is call

Code: ags
  // player chose red car
 
 car = cRedCar;


Similar to the pointer player, car now points to the character cRedCar so all you call is car.Walk.
Again, if you don't really need three car characters in the first place, create a single car character and change their views. You don't need the pointer in that case, you simply use the script name directly.

barefoot

Very informative Khris.. Thanks very much.

Splash screen shows 3 cars (stationary objects) from which to pick. It's like when you helped me do a 'select team' script (difficulty int.)

Each object is a car.

As you and matti stated: just have 1 main player (SetAsPlayer) but change it's views for car colour picked. I would need to Add views for each coloured car (including Idle.)

I will look further into pointers and thank you again for your help.

:=

barefoot



I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk