I'm trying to create a bank that stores a certain unit's kills and reloads them on the next run.
The kills are saved in the file, but not opened by the hero when the game starts.
After hours of debugging, I can comfortably say that the problem is that the game does not give my hero the saved kills.
I'm using a hero selector for my map, which means that the bank has to open after the player has chosen his hero.
The code for opening the bank looks like this:
Bank-Openbank"nameofbankhere"forplayer(Triggeringplayer)General-If(Conditions)thendo(Actions)elsedo(Actions)If(Bank(Lastopenedbank)has"Kills"insection"Player")==trueThenUnit-SetHeroes[1]Killsto(Real((Load"Kills"ofsection"Player"frombank(Lastopenedbank)asintegervalue)))UI-Display"Bank opened from dialog"for(Allplayers)toChatareaElse
The Heroes variable is set to whatever unit that's spawned by a player. In my case, since I'm player 1, the hero will be "Heroes[1]".
I know this is the case, because I ran a check looking for who the variable was set to, and it returned as my hero.
When this code is run, the Text Message telling me so appears, but my hero doesn't gain any kills.
Can anyone see what my problem might be?
Sorry for bumping this but I really can't figure out the problem.
I forgot to mention though, that I have already "Preloaded and synchronized" the bank from map init.
If anything is unclear, please ask me about it, I realise it's probably not the easiest-read thread on the site.
its better if you just set a global variable as kills instead of a bank and use that integer to reload kills. There is really no reason to make a bank unless u want to reload them into the next game they play.
If you do want bank anyway you should instead do save unit option and just reload the unit that is saved back up
I can't use a global variable, because they don't continue their values onto the next game. A bank takes and stores values for the next time the player wants to play the game, which is exactly what I need.
I also have to store the hero's kills as an integer value, rather than store the entire unit, because I only want the kills to be restored.
Essentially, what I want is that, whenever a player kills a unit with his hero, +1 integer value is added to his file. (This works just fine).
Then, after the player has selected his hero for his next playthrough, I want the kills to carry on to that hero.
With the Heroes array (Heroes[1], [2] etc.), I can't tell exactly which hero is being used.
I could, technically, find out using a bunch of crazy checks and variables.
However, I don't want to spend that much effort on it and then realise it's not needed.
You need to open your bank at map init I think.. At least once, then it works from there on I believe.
There are a few weird things about banks, but when you get around those, they are pretty logical
The name of the bank is not stored in a variable, but directly copied/pasted from other sources.
How do you mean when you say "player number"?
My main variable depends on the player number, and has an array of [4] for each player.
@grenegg
That is the exact tutorial I used to get thus far, however it does not go into as much detail as how to explain how I'm supposed to open the bank for a hero set from a menu after the map init.
@JakeCake26
I tried what you said, but still nothing is loaded unto my hero.
Yes, that was also mentioned specifically in the tutorial.
In my map init, the first 4 functions are exactly
"Preload and Synchronize "BankName" for player 1"
"Preload and Synchronize "BankName" for player 2"
etc.
As I mentioned in my OP, the problem is not in openng the bank, but the fault is in the variable.
After running a debug, I am completely certain that the problem is not opening nor saving the bank, so it has to be the variable.
But it's so simple, it takes whoever spawned the hero and adds that player in the specific array.
Unit-Create1(UnittypeofHeroUnits[Playerviewing[(Triggeringplayer)]])forplayer(Triggeringplayer)at(RandompointbetweenPoint011andPoint010)facing95.0degrees(NoOptions)Variable-SetHeroes[(Triggeringplayer)]=(Lastcreatedunit)Bank-Openbank"banknamehere"forplayer(Triggeringplayer)General-If(Conditions)thendo(Actions)elsedo(Actions)If(Bank(Lastopenedbank)has"Kills"insection"Player")==trueThenUnit-SetHeroes[1]Killsto(Real((Load"Kills"ofsection"Player"frombank(Lastopenedbank)asintegervalue)))UI-Display"Bank opened from dialog"for(Allplayers)toChatareaElse
The UI Display message does work, which means the If-Then-Else statement is correct.
Also, how I know that my hero is the correct variable is through this code:
UnitGroup-Pickeachunitin(Selectedunitsforplayer1)anddo(Actions)ActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfHeroes[1]==(Pickedunit)ThenUI-Display"Heroes[1] has been set to Jim Rayno..."for(Allplayers)toChatareaElseUI-Display"Jim Raynor is not set"for(Allplayers)toChatarea
In-game, every 5 seconds, if I have my hero selected, it gives me a message saying that Heroes[1] is set to my hero, which is exactly what I want.
I can't see any problem with any of the code, which is why I'm so confused as to why it won't work.
Thank you so much for that debugging message, it turns out the entire problem was just that Player 4's hero was overwriting Player 1's, thanks to a typo.
Also, about your first notice, I only changed it to that because of testing purposes and, of course, it should be Triggering Player.
Thanks for all your help.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I'm trying to create a bank that stores a certain unit's kills and reloads them on the next run.
The kills are saved in the file, but not opened by the hero when the game starts.
After hours of debugging, I can comfortably say that the problem is that the game does not give my hero the saved kills.
I'm using a hero selector for my map, which means that the bank has to open after the player has chosen his hero. The code for opening the bank looks like this:
The Heroes variable is set to whatever unit that's spawned by a player. In my case, since I'm player 1, the hero will be "Heroes[1]". I know this is the case, because I ran a check looking for who the variable was set to, and it returned as my hero.
When this code is run, the Text Message telling me so appears, but my hero doesn't gain any kills. Can anyone see what my problem might be?
Sorry for bumping this but I really can't figure out the problem. I forgot to mention though, that I have already "Preloaded and synchronized" the bank from map init.
If anything is unclear, please ask me about it, I realise it's probably not the easiest-read thread on the site.
@Ccx55: Go
its better if you just set a global variable as kills instead of a bank and use that integer to reload kills. There is really no reason to make a bank unless u want to reload them into the next game they play.
If you do want bank anyway you should instead do save unit option and just reload the unit that is saved back up
I can't use a global variable, because they don't continue their values onto the next game. A bank takes and stores values for the next time the player wants to play the game, which is exactly what I need.
I also have to store the hero's kills as an integer value, rather than store the entire unit, because I only want the kills to be restored.
Essentially, what I want is that, whenever a player kills a unit with his hero, +1 integer value is added to his file. (This works just fine). Then, after the player has selected his hero for his next playthrough, I want the kills to carry on to that hero.
With the Heroes array (Heroes[1], [2] etc.), I can't tell exactly which hero is being used. I could, technically, find out using a bunch of crazy checks and variables.
However, I don't want to spend that much effort on it and then realise it's not needed.
did you store the bank name or player number in a variable? this doesn't work in preload.
@b0ne123
The name of the bank is not stored in a variable, but directly copied/pasted from other sources. How do you mean when you say "player number"?
My main variable depends on the player number, and has an array of [4] for each player.
@grenegg That is the exact tutorial I used to get thus far, however it does not go into as much detail as how to explain how I'm supposed to open the bank for a hero set from a menu after the map init.
@JakeCake26 I tried what you said, but still nothing is loaded unto my hero.
it must say:
Yes, that was also mentioned specifically in the tutorial.
In my map init, the first 4 functions are exactly "Preload and Synchronize "BankName" for player 1" "Preload and Synchronize "BankName" for player 2" etc.
As I mentioned in my OP, the problem is not in openng the bank, but the fault is in the variable. After running a debug, I am completely certain that the problem is not opening nor saving the bank, so it has to be the variable.
But it's so simple, it takes whoever spawned the hero and adds that player in the specific array.
add some debug messages, maybe something is called in the wrong order or does no longer exist. maybe publish some more code
My main batch of code is this:
The UI Display message does work, which means the If-Then-Else statement is correct.
Also, how I know that my hero is the correct variable is through this code:
In-game, every 5 seconds, if I have my hero selected, it gives me a message saying that Heroes[1] is set to my hero, which is exactly what I want.
I can't see any problem with any of the code, which is why I'm so confused as to why it won't work.
does the kill number show up if you replace the bank opened text:
@b0ne123: Go
Thank you so much for that debugging message, it turns out the entire problem was just that Player 4's hero was overwriting Player 1's, thanks to a typo.
Also, about your first notice, I only changed it to that because of testing purposes and, of course, it should be Triggering Player.
Thanks for all your help.