Page 1 of 1
Code Help
Posted: Wed Jan 04, 2023 11:33 pm
by TrailScout
Why?! Why?! Why? For the love of Pete Why isn't this working?
Place a predefined Unit on Cities. It Should be So Simple!
Tell me whats wrong please.

- SS Place City.png (199.07 KiB) Viewed 1110 times
Re: Code Help
Posted: Thu Jan 05, 2023 5:05 am
by ernieschwitz
You have the event set to No Check. So if you are running it during the turn, it won't execute. But you may be using it to Execute from inside the editor?
You may have done another error. Are you sure that unit 2 is the same as your predefined unit 2? You are using it's number in line 6, but predefined in line 7. Not sure this would cause the event not to place a unit though.
Re: Code Help
Posted: Thu Jan 05, 2023 3:40 pm
by TrailScout
Yes I am running this from inside the editor at this point, It will go live later.
Line 6 is supposed to change the people of predefined unit to the same as the regime (TempVar3) before it is placed.
Line 7 should then place the unit.
The goal is to Scan the Map. Identify Cities. Place a Predefined Unit on Cities (within the random %)
It is not reading the regimes or changing the predefined unit people so it is dropping a “German” Unit onto a “Chinese” hex.
Very frustrating!. LOL. Should be so easy Im just not getting something right.
Re: Code Help
Posted: Thu Jan 05, 2023 5:33 pm
by ernieschwitz
I ran some tests.
There are two instances where this code does not do what you want, that is place a unit. First is that there is no predefined unit 2. The second is that the map does not contain any location which is identified as type 0.
Therefore check there is actually a predefined unit 2 (I am guessing there is, since you must have created it to know what is in it). Then check if there are any locations type 0 on the map. Be aware that the symbol for "a city" itself, is a graphic thing, and can be present on a map, without there being "a city". In most cases this means that there is landscape there that is called urban.
The ANewDawn masterfile, for instance, does not have any locations on it.
To test this event, remove the specification for it to have a random chance to be placed, so as to eliminate that possibility. Then place a location on the map, doesn't need to be any specific place, as long as you remember the place, and then execute the event.
As for turning the unit's people into that of regime 2. You need the unit number, which is not the same as the predefined unit number. Whenever a new unit is created it gets its own new unit number. Whatever unit you are changing the people of is the same unit throughout the event.
There are several ways to make sure you change the unit to the people you want. If you need help with that, please tell me.
Re: Code Help
Posted: Thu Jan 05, 2023 5:50 pm
by TrailScout
Thanks,
I’ll run some tests after work!
Re: Code Help
Posted: Fri Jan 06, 2023 2:08 am
by TrailScout
I was able to get it to place the Predefined Unit I wanted to on the proper location and the proper regime.

- Place PDUnit 3.png (88.93 KiB) Viewed 1057 times

- predefined3.png (346.14 KiB) Viewed 1057 times
However when it places the Unit on a "French" Hex the unit it places is German. (Because the SFT I built the unit with is German)
How do I change this Unit to French. Or find all the SFT's within the unit and change them from German to French.
The Set Var4 Temp Var4 is doing nothing. No matter how I monkey with it.
I was attempting to do that with the ExecUnitPeopleModify command. However I'm stumped again!
Thanks!
Re: Code Help
Posted: Fri Jan 06, 2023 2:19 am
by ernieschwitz
Am I correct in assuming you only want to run this at round 1, that is before the game begins?
Re: Code Help
Posted: Fri Jan 06, 2023 4:37 am
by TrailScout
Correct, I was going to have it Run at the End of Random Events.
Re: Code Help
Posted: Fri Jan 06, 2023 4:58 am
by ernieschwitz
Ok, this is what you do for a completely generalized event:
Note down the Unit number of the PreDefined Unit. That is the number in ( ) not the number right next to # where you make your predefined unit (so the Unit menu).
Remove the line with
Check TempVar3 = 1 (so it will work for all regimes)
Change the line
TempVar4 = CheckRegimePeople(0) to
TempVar4 = CheckRegimePeople(TempVar3)
Input the line
ExecUnitPeopleModify(A, -1, TempVar4),
where A is the unit number you found that the Predefined unit was (the one in ( )).
Place the Unit A by changing the
ExecAddUnit(3, TempVar0, TempVar1, TempVar3), to
ExecAddUnint(A, TempVar0, TempVar1, TempVar3).
Now it should work.
As you see you were very close

Re: Code Help
Posted: Fri Jan 06, 2023 7:58 am
by ernieschwitz
There is a mistake in my last line of coding (see I make mistakes too). Keep the 3 and manually change it to the predefined unit you want to use...
Re: Code Help
Posted: Fri Jan 06, 2023 1:07 pm
by TrailScout
Ahhhh… I see what you did there! I was not aware that you could put a TempVar in place of the regime # and reference the new tempvar (3).
I cant wait to get home and try this! I’ll be thinking about it all day at work LOL
Thank you!!
Re: Code Help
Posted: Fri Jan 06, 2023 1:12 pm
by ernieschwitz
No problem
And should you run into anything else, I'll be here

Re: Code Help
Posted: Sat Jan 07, 2023 6:45 pm
by TrailScout
Got it! Thanks
Ok. I'm working on my next problem. Ill work at it and get close before I ask for specific help.
I now need to
1.Scan Map for location. (Easy)
2. Determine if the location is adjacent to a Sea Hex (Using the CheckLandscapeAdjacent)
3. If so then deploy a Naval Unit either on the Loc or on a sea hex adjacent and have it belong to the hex owner.
Let the next round of head banging begin!
Re: Code Help
Posted: Sat Jan 07, 2023 6:49 pm
by ernieschwitz
Good luck
