Quantcast

Jump to content

» «
Photo

Checking if a variable is the sum of any combination of variables

2 replies to this topic
matinat0r
  • matinat0r

    Player Hater

  • New Members
  • Joined: 28 Jul 2014
  • Gibraltar

#1

Posted 30 July 2014 - 07:54 PM Edited by matinat0r, 30 July 2014 - 10:32 PM.

Hey there, ran into a bit of a problem.

 

I have 5 variables, [email protected], [email protected], [email protected], [email protected], and [email protected]

 

I want to check if [email protected] is equal to the sum of any combination of the first four variables.

 

Based on what I know in CLEO, the only way I can think to do this is to create variables for every possible value, and then check to see if [email protected] is equal to any of those variables, a bit like this:

0085: [email protected] = [email protected]
005A: [email protected] += [email protected] 
0085: [email protected] = [email protected]
005A: [email protected] += [email protected]
0085: [email protected] = [email protected]
005A: [email protected] += [email protected]
0085: [email protected] = [email protected]
005A: [email protected] += [email protected]
005A: [email protected] += [email protected]
...etc
    
if or
    003B:   [email protected] == [email protected]
    003B:   [email protected] == [email protected]
    003B:   [email protected] == [email protected]
    003B:   [email protected] == [email protected]
    003B:   [email protected] == [email protected]
    003B:   [email protected] == [email protected]
...etc

But not only does that feel a bit messy, it also uses up a lot of vars that I might be needing in other areas of the script. I thought I could do the same thing with just one extra variable and some nested conditionals, so I came up with this:

if 003B:  [email protected] == [email protected] 
then jump @true
else 
    if 003B:  [email protected] == [email protected] 
    then jump @true
    else
        if 003B:  [email protected] == [email protected] 
        then jump @true
        else 
        ...etc
            0085: [email protected] = [email protected]
            005A: [email protected] += [email protected]
            005A: [email protected] += [email protected]
            if 003B:  [email protected] == [email protected]   
            then jump @true
            else
            ...etc
            else jump @false
...   
end

Which is a bit better, as I only use up one more variable, but it's even longer and probably harder to look at than before. What's more, if I come across a similar situation in the future with even more variables to combine, the code is going to get exponentially longer.

 

So, I was wondering if there was any easier, cleaner way to do this. Maybe I'm missing something, or there's just a gap in my knowledge, or maybe I'm approaching this completely wrong. Either way, I'd really appreciate it if anyone could lend a hand.

 

Thanks.


Shmoopy
  • Shmoopy

    Lost interest in GTA

  • Members
  • Joined: 16 Jun 2009
  • None

#2

Posted 31 July 2014 - 01:38 PM Edited by Manfred Von Karma, 31 July 2014 - 01:39 PM.

If the combinations are just of two variables then here is a code :

//[email protected] [email protected] [email protected] [email protected] - [email protected]
$Index = 1 
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[1]
$Index += 1
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[2]
$Index += 1
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[3]
$Index += 1 
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[4]
$Index += 1
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[5]
$Index += 1 
0A8E: $Sum($Index,7i) = [email protected] + [email protected] // [email protected] + [email protected] equals $Sum[6]  
// example :
if
    07D6:   [email protected] == $Sum[1] // [email protected] equals [email protected] + [email protected]    
then

end
if
    07D6:   [email protected] == $Sum[2] // [email protected] equals [email protected] + [email protected]    
then

end
// ...  

If not then it can't be done without a long code .


DK22Pac
  • DK22Pac

    𝘉eчнo 𝘔oлoдoй...

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#3

Posted 31 July 2014 - 10:25 PM

for [email protected] = 0 to NUM_OF_VARIATIONS
    if
        07D6: [email protected] == $Sum[[email protected]]
    then
        // true
        // ...
        break
    end
end
  • Shmoopy likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users