Code Help

Discuss and post your mods and scenarios here for others to download.

Moderator: Vic

Post Reply
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Code Help

Post 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
SS Place City.png (199.07 KiB) Viewed 1107 times
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post 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.
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post 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.
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post 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.
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post by TrailScout »

Thanks,

I’ll run some tests after work!
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post by TrailScout »

I was able to get it to place the Predefined Unit I wanted to on the proper location and the proper regime. :D
Place PDUnit 3.png
Place PDUnit 3.png (88.93 KiB) Viewed 1054 times
predefined3.png
predefined3.png (346.14 KiB) Viewed 1054 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!
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post by ernieschwitz »

Am I correct in assuming you only want to run this at round 1, that is before the game begins?
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post by TrailScout »

Correct, I was going to have it Run at the End of Random Events.
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post 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 :)
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post 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...
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post 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!!
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post by ernieschwitz »

No problem :)

And should you run into anything else, I'll be here :)
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
TrailScout
Posts: 12
Joined: Sun Apr 04, 2021 9:24 pm

Re: Code Help

Post 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!
User avatar
ernieschwitz
Posts: 4533
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

Re: Code Help

Post by ernieschwitz »

Good luck :)
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
Post Reply

Return to “Mods and Scenarios”