Jump to content
Sign in to follow this  
PowerMage

Problem with float values.

Recommended Posts

I have been working a while on a new mission where I use logical units dammage to represent a state.

For example I use setDammage 0.99 to tell the logical Unit that it's on the west side (dammage is checked by a skript run with this unit).

In Singleplayer everything works fine and all states are recognized correctly but in multiplayer these values seem to change. I set the dammage of a unit to 0.99 and let it draw it's dammage on screen but on screen it had a value of 0.988189. This only happened in Multipalyer. In Singleplayer the value is shown correct with 0.99. Is this a bug or is it a feature?

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">In Singleplayer everything works fine and all states are recognized correctly but in multiplayer these values seem to change. I set the dammage of a unit to 0.99 and let it draw it's dammage on screen but on screen it had a value of 0.988189. This only happened in Multipalyer. <span id='postcolor'>

This may be result of compression used on values when transferred accross network. In MP you are not guaranteed any float value will be exactly the same when viewed from different computers.

Share this post


Link to post
Share on other sites

And anyway do you really need such a high level of precision? It an error of 0.2%.

David Vrabel

Share this post


Link to post
Share on other sites

Well, I needed this precission because I used float values to represent a state. The value 0.99 i.e. meant that a city was captured by west and 0.98 meant that the city was east. It was easy to preconfigure the cities with these values by setting the dammage to the logical unit. Anyway... I use now big big arrays to store all data and update these arrays when something changes. It was a bit hard to figure out how I can do this without getting a mess when client and server scripts are working the same time but now it works very fine.

I have a little question:

When you're running a skript and you do a critical section, which means that you update a large array with new data (replace one entry with new one in the middle of that array) and it's possible that skripts that are running in the same time might do the same thing with that array. Now my question is if the skripts aren't interrupted unless they have a wait command (~) or are finnished there is no big problem because it's ensured that only one skript at a time has access to these arrays and nothing can be overwritten or skipped. Since 1.45 I read that skripts won't freeze the game anymore if they enter a infinite loop without a wait command. Is this feature enabling the skripts to switch threads (meaning you execute skript1 and then ofp allows skript2 to be executed and than skript1 again without the wait command). If this is so than I can't have my critical sections anymore. I didn't use wait commands in my loops while updating the array to insure that my skript isn't interrupted by another skript that is trying to do the same.

It would be nice to know a bit about these things.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Since 1.45 I read that skripts won't freeze the game anymore if they enter a infinite loop without a wait command. Is this feature enabling the skripts to switch threads (meaning you execute skript1 and then ofp allows skript2 to be executed and than skript1 again without the wait command). <span id='postcolor'>

Yes, there is script switching - but is is predictable. You are guranteed 100 lines will be executed unless there is wait command, so normally there is no need to worry.

Share this post


Link to post
Share on other sites

Well... 100 lines... so I guess when I'm running a loop that modifies an array with about 20 entries and the code for the loop is about 5 lines so I run this loop 30 times in worst case (when the element I'm searching for is at the end and that element is an array itself). Now I have 150 Lines for the expression evaluator to interpret so it will switch to another skript after 100 lines. The problem is now that I can't let the skript be interrupted because there might be another skript just doing the same thing. I don't wanna explain the stuff with critical section and semaphores now because I think you already know what I mean. It's just that this way simultaniously running skripts might produce garbage with my arrays if they are interrupted while updating an array list.

Is there any possibility to avoid these problems?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×