Custom Objective help!

The Apocalyptic · 293

The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Custom Objective help!
on: April 20, 2022, 05:17:50 pm
I've decided that my new map, which I'll be releasing before the one I asked for help with previously, needs a custom objective. However, the objective automatically completes, even when the conditions should not allow it.

The code, without giving away any unit IDs or the objective name, is:

Code: [Select]
if (GetUnitAmmo(self) eq 1000)
AcquireMissionObjective(5 true)
true ->acquired
endif

if (<-acquired)
SetCustomObjectiveText("CustomObjective          <color=#00ff00>")
endif

The code is attached to the unit in question.
« Last Edit: April 20, 2022, 05:26:16 pm by The Apocalyptic »



Karsten75

  • Hero Member
  • *****
    • Posts: 7321
Re: Custom Objective help!
Reply #1 on: April 20, 2022, 07:44:39 pm
I've decided that my new map, which I'll be releasing before the one I asked for help with previously, needs a custom objective. However, the objective automatically completes, even when the conditions should not allow it.

The code, without giving away any unit IDs or the objective name, is:

Code: [Select]
if (GetUnitAmmo(self) eq 1000)
AcquireMissionObjective(5 true)
true ->acquired
endif

if (<-acquired)
SetCustomObjectiveText("CustomObjective          <color=#00ff00>")
endif

The code is attached to the unit in question.


Simple coding error.

Code: [Select]
if (GetUnitAmmo(self)  1000 eq)
AcquireMissionObjective(5 true)
        SetCustomObjectiveText("CustomObjective          <color=#00ff00>")
endif


'If you want to live a happy life, tie it to a goal, not to people or things.'

Albert Einstein
(1879-1955)


Vertu

  • Full Member
  • ***
    • Posts: 233
Re: Custom Objective help!
Reply #2 on: April 21, 2022, 09:44:06 am
Unless the unit involved here has an obvious max ammo cap of 1,000, I recommend not using "eq" and instead using "gte" unless you are certain that it will happen specifically at that condition, such as a unit's max ammo being EXACTLY 1,000 but if not and the unit removes ammo via non-integer math, you can get runaway float numbers like 10.000001 which would require the use of the API "Approximately" or a logic of "gte". This does not apply to when at max ammo because the game forces the current ammo into either; an integer if the max ammo is an int, or into the exact number of the maximum ammo, cleaning up runaway floats.

Also you need to put the color format in front of the text you want to color as you then use </color> to "close" this "color block" much like and EndIf for an If block.
Furthermore, I believe that your use of a number other than 0 in the "eq" logic is wrong and needs parenthesis. I have done typos of not including them like with "eq 1000" and being given an error or very weird results until I changed it to "eq(1000)". It has been a good while since I have done this mistake so things could of changed.
Your use of "<-acquired" is unnecessary as whenever you call the API AcquireMissionObjective(5), ideally within the same logic block, you set the custom objective text to green as they are mutually inclusive events. So having "<-acquired" just adds an unnecessary extra step. You should also ideally add an Once - Endonce block after the If block so the script doesn't unnecessarily repeat this process even if KnuckleKracker compensated the API for such a mistake from new coders. Especially when making that area more complex, such as showing an in-game message after completing the custom objective.

Here is how I would of coded this section with your provided information, and I have gained a lot of confidence with this style's effectiveness.
Code: [Select]
if(GetUnitAmmo(self) gte(1000))
        once
        AcquireMissionObjective(5 true)
        SetCustomObjectiveText("<color=#00FF00>CustomObjectiveText")
        endonce
endif

If you test to see if any objective triggers in the editor, the only way to revert the objective(s) status is by clicking the "Reset Map Data" button. So it would be best to make a scratch save or a normal save just before doing these kinds to then load back into once the testing is done. Any changes in code for the scripts will be auto-recompiled upon loading into the previous save, which also means if you do a change which breaks something upon loading the save, don't panic, fix it without saving in the code and then reload the save.
Also be sure to recompile scripts via CTRL + R or what ever button mapping you set it for if you changed it as recompiling from the CPack editor menu had some.. interesting and harmful results in the long run when making many maps with that CPack afterwards.

If it still auto acquires and you have other CPacks, be sure to have a quick look through all the CPack scripts in case they are doing it and not your own script. This was very important during my creation of VPAC as the original PAC CPack had 2 different scripts responsible for AquireMissionObjective(5) which frustrated and confused me to the extreme until I found out a 2nd script which shouldn't be responsible for such a role had this API call. I don't want you to experience this so I included it here just in case.

Life isn't fair because we say it isn't. Not because it is unfair. In fact, it is so fair we want to say it isn't and do.


The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Re: Custom Objective help!
Reply #3 on: April 21, 2022, 07:35:11 pm
That did the trick. Thanks!



The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Re: Custom Objective help!
Reply #4 on: May 04, 2022, 11:17:01 am
Now, despite being set otherwise, the unit for the custom objective won't connect to the network!

Edit: Never mind. Was just connecting in the wrong spot.
« Last Edit: May 04, 2022, 11:19:53 am by The Apocalyptic »



The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Level Fully Debugged! Testing will ensue shortly!
Reply #5 on: May 07, 2022, 12:44:40 pm
I finally removed all the bugs from the level. Next up, starting 05/09/2022, is the final playtesting, for both single player and M-Verse. Volunteers for the latter are most welcome, and should reply to this thread to do so. I will PM people to coordinate times.



Karsten75

  • Hero Member
  • *****
    • Posts: 7321
Re: Level Fully Debugged! Testing will ensue shortly!
Reply #6 on: May 07, 2022, 12:55:49 pm
I finally removed all the bugs from the level. Next up, starting 05/09/2022, is the final playtesting, for both single player and M-Verse. Volunteers for the latter are most welcome, and should reply to this thread to do so. I will PM people to coordinate times.

Discord has a channel and a role that allows one to send specific messages to solicit Mverse players. Not that it is heavily used, mverse is kind of niche

'If you want to live a happy life, tie it to a goal, not to people or things.'

Albert Einstein
(1879-1955)


The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Re: Custom Objective help!
Reply #7 on: May 09, 2022, 04:12:44 pm
For some reason, Discord will neither let me log in nor reset my password.



The Apocalyptic

  • Full Member
  • ***
    • Posts: 33
Re: Custom Objective help!
Reply #8 on: May 17, 2022, 04:41:15 pm
I'm attempting to make it so the unit for the custom objective requests packets faster, but when I try to do this, it doesn't work.

Perhaps because I'm attempting to get it to accept 28 packets over the course of 30 frames, instead of going for the 30?

Or perhaps because I didn't bother calculating the value myself.