Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: on Tue 05/06/2007 18:42:57

Title: Small integer/float problem
Post by: on Tue 05/06/2007 18:42:57
Hello! I have a quick question about Integers, which I never understand! In my game, I need it to do a bit of math. I need it to make a division by 1.2 but I'm not sure how.

What I thought it should be is;
if (GetGlobalInt(298)>(adpriceypoo.Value / 1.2)) {

but naturally that doesn't work. So I looked over the FloatToInt section etc but I don't really understand it. This code saved alright;

int number = FloatToInt(1.2);
if (GetGlobalInt(298)>(adpriceypoo.Value / number)) {

But it didn't work in game. I'm not entirely sure what's going on but I presume it's just rounding "number" down to 1?

Can someone give me a quick pointer as to how I can get my code to work out a division of 1.2 in a sliders value?

Any help appreciated, thank you!!

ps, I will "remove" this thread once I've got a solution :)
Title: Re: Small integer/float problem
Post by: Ashen on Tue 05/06/2007 18:47:32
How about going the other way with it:

float TempF = IntToFloat(adpriceypoo.Value)/1.2;

if (GetGlobalInt(298)> FloatToInt(TempF)) {
...
}


Works out the sldier value / 1.2, THEN converts to an int (round down by default, or add the eRoundNearest parameter).
Title: Re: Small integer/float problem
Post by: on Tue 05/06/2007 18:53:43
Gotcha! Works a treat, thanks Ashen :)
Title: Re: Small integer/float problem
Post by: on Tue 05/06/2007 19:02:31
One further question, one I can probably bust myself if I think about it hard enough, but maybe you can suggestion something Ashen. Regarding the code you've just seen...

Lets say adpriceypoo Value is "100". The code then basically looks to see if the Random int thingy is more than 83 (if 100 is being divided by 1.2).

If adcpriceypoo Value is "200" then the code looks to see if the Random int thingy is more than 166.

This division is made at the following key "adpriceypoo" points. 100, 200, 500, 1000 and 1750. In theory, the lower the adpriceypoo, the LESS likely you would be to HIT the random divided integer, and the more adpriceypoo Value there is then the MORE likely you are to hit a number. I beleive this works because 83 to 100 is 17 possible hits, 166 to 200 is 34 possible hits etc...

Only problem is, it seems to be "hitting" just as frequently for the lower adpriceypoo value as it is for the highest. Do you know of anyway I could slow it down/make sure there is a considerably less chance to get a "hit" with a lower adpriceypoo.Value?

Hope that makes sense :p Many thanks.
Title: Re: Small integer/float problem
Post by: Ashen on Tue 05/06/2007 19:22:32
Double posting, tsk tsk. :)

Your second post reads like GlobalInt 298 is Random(adpriceypoo.Value), right?

Because you're always dividing by the same amount (1.2) won't TempF always be the same percentage of the initial value? (I.e. it'll always be 83% of adpriceypoo.Value) So, the probablity of getting higher will always be 17%, it's equally likely whatever the value of adpriceypoo.Value.

The only way to make lower values of adpriceypoo less likely, would be to always use the same value for the maximum random number (SetGlobalInt(298, Random(1750), or whatever the highest value is), or to vary the 1.2 based on adpriceypoo.Value.
Title: Re: Small integer/float problem
Post by: on Tue 05/06/2007 20:04:19
Thanks dude. Well, I thought that when it made the division, the number the GlobalInt would look for to find out whether it can proceed or not would be the actual number that adpriceypoo / 1.2 would hit, rather than a percentage.

I don't fully understand this, or what you've just told me, but I'll try & figure something out :)

Edit - oh and I can't remove this thread after-all :p But it can be removed now. I'm making progress. Thanks for your help yet again Ashen!!!
Title: Re: Small integer/float problem
Post by: Gilbert on Wed 06/06/2007 02:00:03
Instead of removing it I'll just lock it instead.
So it will be recorded in history that m0ds did ask technical questions once a while (j/k). :=

Well, actually I'll leave it in case people may have similar problems so they can still read it (maybe after searching) or when you need to add something, just PM for reopening.