Logo Platform
logo amplifiers simplified

[HELP] Best way to do "if-else" statements?

Reply
Copied to clipboard!
10 years ago
Jan 8, 2015, 10:27:32 PM
Ive done programming in a few languages but never xml. From what I understand generally xml does not use comparators.



Any suggestions on how I would do something where I would normally use an if-else statement?

The following is a general "Pseudo" Code of what I want to do:



IF [X<1] THEN

[Approval=Approval+'ModifierDescriptorA']

ELSE

[Approval=Approval-'ModifierDescriptorB']







The tutorial isn't clear on the exact use of InterpreterPrerequisites. Would I use these to do this? How would I use them?
0Send private message
10 years ago
Jan 13, 2015, 9:56:03 AM
Hello Caotico,

To be short there is no possibility to code by modding. Through xml you can only use the tool at disposal.

If you want to make a building which gives different bonus according to values it won't work...

I will try to give a bit more explanations on interpreter prerequisites.



PS: I've seen your message but need to gather proper info from our programmers which can took some time.
0Send private message
10 years ago
Jan 13, 2015, 2:14:52 PM
From looking at the various code examples, interpreterprerequisites seem like the only way I might be able to make it work.

It seems that the Quests basically use an "if" statement. If this condition is true then apply these values.



I was hoping I could do something similar to this:



Example code from Quest Definitions [FromInteract]

[code]



.../ClassEmpire,AffinityBrokenLords

$MaxProperty(EmpireTypeMajor/ClassCity:Population) ge 6

$MaxProperty(EmpireTypeMajor/ClassCity:Population) ge 8





...















[/code]



Where I would do something like

[code]

InterpreterPrerequisite Flags="Prerequisite">$MaxProperty(EmpireTypeMajor/ClassCity:Population) ge $MaxProperty(EmpireTypeMajor/ClassCity:CMGarrisonCount

[/code]

Then put approval as an award...
0Send private message
10 years ago
Jan 15, 2015, 2:09:30 PM
Indeed, interpreter prerequisite can be seen as an "if" because in the quests it is used to check some specific situations. If the condition is ok and it ends the step a reward can be given. But this is very specific to the quest.

There is no way to apply something directly after an interpreter prerequisite through xml :/
0Send private message
10 years ago
Jan 15, 2015, 2:31:58 PM
Pikou wrote:
Indeed, interpreter prerequisite can be seen as an "if" because in the quests it is used to check some specific situations. If the condition is ok and it ends the step a reward can be given. But this is very specific to the quest.

There is no way to apply something directly after an interpreter prerequisite through xml :/




Could you have a "fake quest" that didn't have any GUI elements, and activated for each city every turn? If the condition was true the city gets an approval bonus?
0Send private message
10 years ago
Jan 15, 2015, 4:05:57 PM
Indeed you can make invisible quests (hidden ones to be more precise).

But several problems should occur considering your requirements:

1) You can have a reward only at an empire level and approval is not a stock value

2) There will be 1 turn delay because trigger to validate the quest will be linked to the beginning of next turn

3) Quest can only be triggered at an empire level



Might be interesting to try something a bit different maybe?

Rewarding science or else...
0Send private message
10 years ago
Jan 16, 2015, 12:34:33 AM
Dang. Was hoping that would work.

So you cant make quest that affect anything below empire level?

There were a few ideas i had hoped to try at some point... (ie: Boost a cities production of a resource for a set of turns, Completing a current production item on a city, make a city immune to siege negative effects for a period, etc)



Pretty disappointing that you cant implement anything beyond simple addition/subtraction/multiplication/division as well. Was really interested in making the approval thing work out and doing alot of testing on it.



The only other thought i had was- could you basically skip the Quest->City interaction by introducing new variables at the Empire Level?

Could you create an array on the empire level that pulled info from the city level (ie, each cities approval ratings) at each turn end? This array could interact with the quest at the beginning of each turn and store information in another array at the empire level. Then each city would modify approval ratings based on the new array.



How do the quests that check for district level upgrades work from the empire level?
0Send private message
10 years ago
Jan 16, 2015, 10:12:44 AM
Well... As you have already discover we does not give you a whole coding framework to work with...



Indeed, quest can be used to make some sort of programming. Like you said, if you use wisely the prerequisites and the quest action you could do some sort of interactivity.

Basically Quest are designed to work on an empire. It is not owned by the object which triggered it, but by the empire which own the object. That does not means that you cannot target a specific city inside the quest.



The available actions are indeed limited by what our designers asked us to give them (and by how much time we have to invest in the quest system too...). As for now, there is no action in the quest framework which is able to activate a booster, give a building to a city or simply boost some resource gain on a defined city. But it does not mean that we cannot do it...



Now back at what you want to create.

If I understand correctly the idea is:

-> Check that a defined condition is respected on a city and then boost the "Approval" of the defined city.

Well, when I read that I want to say: "Yes sure you can"... but unfortunately forcing the activation of a booster on a targeted city in a quest is not currently possible. The only thing I can think of for now is giving some "Luxury" which allow the approval to be increased when the player will activate the luxury booster.



I will talk with Pikou about it and we will try to include this our overtime work as I am kind of baffled we didn't already implement it^^. It should not be too difficult to do and will increase the possibilities of the quest system.



We'll keep you informed about the status of the new action.



Thanks for sharing your thoughts and taking the time to do stuff with our game!!! it is always rewarding to see people pushing our system a little further ^^



Cheers,

flo.
0Send private message
10 years ago
Jan 16, 2015, 10:20:27 AM
By the way, Pikou just forwarded me your PM. I will look into it and try to write you an answer about a solution (or at least I hope I can find one ^^).



See you "soon" ^^
0Send private message
10 years ago
Jan 16, 2015, 11:19:45 AM
Here is a short description of what you want to do, so other people can understand the whole thing.



The idea is to modify the approval of a city based on the population and the number of unit in the garrison.

Here is the formula you come with:

[CODE]

=IF ((POPCOUNT-1)-POLICECOUNT)<1)

THEN

ApprovalBonus = (15*(POPCOUNT-1))-(POPCOUNT*7.5)

ELSE

ApprovalBonus = (15*POLICECOUNT)-(POPCOUNT*7.5)) where POPCOUNT is capped at 14 and POLICECOUNT is capped at 8.

[/CODE]



The police count is the number of units in the garrison.



Here is my solution which is basically what you have done with one or two modifications.

[Code]

In the file: SimulationDescriptors[Class].xml

Add these lines in the SimulationDescriptor named ClassCity between the xml tag "SimulationPropertyDescriptors".





























Add these lines int he SimulationDescriptor named ClassCity between the xml tag "SimulationModifierDescriptors"













































[/Code]



Remarks:

- I have skipped all the paths because we are always working on the city so no need to use them. You can put them in if you want to be fully explicit.

- I have added the UnitSlotCount property on the city to avoid error when other part of the code use the city class descriptor only (for economic projection we don't need the garrison part normally...)



Here is the xml file for reference.

SimulationDescriptors[Class].zip



Let me know if something is not working!



Cheers!

flo.
0Send private message
10 years ago
Jan 16, 2015, 1:24:04 PM
Wow. You guys are awesome! Thanks thortillas and pikou! smiley: biggrin





I will look through it in more detail (and give it a try), I might have questions. But wanted to post a 'thank you' first of all.



Edit:

The use of the toggle and multiplication by zero is very clever. I hadn't thought to do anything like that.
0Send private message
0Send private message
10 years ago
Jan 20, 2015, 2:10:19 PM
Have only one issue so far.



1) When garrisoning units, if the units move an approval state (say from strike to happy), the bar doesn't change colors or the text update until I advance turns. I assume this is because its part of the endturn calculations... any way I can make it update midturn?



2) I want to decrease the upkeep cost of units in garrison without decreasing the upkeep cost of units outside of garrisons. Any suggestions?
0Send private message
10 years ago
Jan 22, 2015, 8:21:27 AM
1) Well. that's the problem with approval. It's not possible to compute the whole approval stuff in the simulation so we have to launch an algorithm every time the Approval value change.

Apparently, we have not bound the approval computation on the modification of the number of unit in the garrison. I'll see if I can do something about that for a futur patch.



2) Yep easily. You can:

-> Add a modifier on the city class descriptor which reduce the upkeep of all the unit under the city with the path : ClassCity/ClassUnit

-> Add a modifier on the empire class which reduce the upkeep of all the unit under all the city with the path : ClassEmpire/ClassCity/ClassUnit

-> Same with an improvement : ../ClassCity/ClassUnit

-> ect...

Does that answer your question?



Cheers!

flo.
0Send private message
10 years ago
Jan 25, 2015, 1:11:53 AM
Thortillas,



Yes that helps, Thanks.



I have a bigger issue unfortunately. The update broke my mod (or made it give a weird bug).



Mod worked fine. When game updated i copied all the new files and made the same changes to them.

I used a file comparator to make sure the files were exactly the same except for my line additions.



The issue occurs with Broken Lords. You cant increase population (gold is spent but population stays at one).

The normal game works fine, but loading the mod doesnt.

I have narrowed down the culprit to be the Simulation[Class] file (it works when replaced with normal one).

So i redid the Simulation[Class] file. I started with the standard file and added the below lines to it... and again it broke the BL population increase.



...and unfortunately i dont have the un-updated Simulation[Class] file to compare against.



Within ClassCity SimulationPropertyDescriptors

[code]

































[/code]



Within ClassCity SimulationModifierDescriptor

[code]

















































[/code]



Ive attached the mod and a saved game.
Anti-EXP 1.zip
Anti_Expansion_Mod.zip
0Send private message
10 years ago
Jan 26, 2015, 1:59:35 PM
Hi!



I loaded your save with your mod and get this error:

[CODE]

Date: 02:51:06.038

FileName: E:\SVN\EndlessFantasy\Development\trunk\Unity Project\Assets\Plugins\Endless Framework\Amplitude.Unity.Simulation\SimulationObject.cs:1215

MethodName: InsertDependancy

Message: Invalid target name: CMModPopCount on object City#294.

[/CODE]



I think you have a modifier which should not be there or you should declare the property CMModPopCount which does not exists.

[Code]





[/Code]



Have a nice day!

flo.
0Send private message
?

Click here to login

Reply
Comment