Author Topic: Make object be destroyed if the player has any amount of secrets less than 8?  (Read 1829 times)

l3agu32

  • Wannabe
  • Posts: 22
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
  • Playstyle: Keyboard
I made an object be destroyed when I have all 8 secrets. But when I try to make an object be destroyed when I have any amount of secrets less than 8, it is destroyed only when the amount of secrets is 7. Thank you!

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
  • Playstyle: Keyboard
Since you haven't provided any code, I can only speculate that the problems is being caused by the indexes used for most secrets starting at 0, and your count starting at 1. You should really provide code when asking a question like this though.

l3agu32

  • Wannabe
  • Posts: 22
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
  • Playstyle: Keyboard
Since you haven't provided any code, I can only speculate that the problems is being caused by the indexes used for most secrets starting at 0, and your count starting at 1. You should really provide code when asking a question like this though.
This is the code I tried, and as I said I want it to make the object be destroyed if the amount of true secrets is less than 8, but the object is being destroyed only when the amount is exactly 7 true secrets. I didn't find some way to count variables like we can count instances using "instance_number".
Code: [Select]
if global.secretItem[1] = true
if global.secretItem[2] = true
if global.secretItem[3] = true
if global.secretItem[4] = true
if global.secretItem[5] = true
if global.secretItem[6] = true
if global.secretItem[7] = true
if global.secretItem[8] = true{
//nothing happens
}
else{
instance_destroy()}
« Last Edit: July 12, 2016, 09:37:09 AM by l3agu32 »

Nogard

  • Wannabe
  • Posts: 27
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
    • Twitch
  • Playstyle: Keyboard
This is the code I tried, and as I said I want it to make the object be destroyed if the amount of true secrets is less than 8, but the object is being destroyed only when the amount is exactly 7 true secrets. I didn't find some way to count variables like we can count instances using "instance_number".
Code: [Select]
if global.secretItem[1] = true
if global.secretItem[2] = true
if global.secretItem[3] = true
if global.secretItem[4] = true
if global.secretItem[5] = true
if global.secretItem[6] = true
if global.secretItem[7] = true
if global.secretItem[8] = true{
//nothing happens
}
else{
instance_destroy()}

I suggest you to start indenting your code. What happens is this:
Code: [Select]
if global.secretItem[1] = true
  if global.secretItem[2] = true
    if global.secretItem[3] = true
      if global.secretItem[4] = true
        if global.secretItem[5] = true
          if global.secretItem[6] = true
            if global.secretItem[7] = true
              if global.secretItem[8] = true
               {
                  //nothing happens
               }
              else
              {
                 instance_destroy()
              }
The else statements affects only the last if, so the code gets executed if and only if the first seven secrets are true and the last one is false.

You could use this to simplify things:
Code: [Select]
if(!(global.secretItem[1] == true &&
     global.secretItem[2] == true &&
     global.secretItem[3] == true &&
     global.secretItem[4] == true &&
     global.secretItem[5] == true &&
     global.secretItem[6] == true &&
     global.secretItem[7] == true &&
     global.secretItem[8] == true))
  {
    instance_destroy();
  }
! is the logic negation, && the logic AND
The instance_destroy() line will get executed if any of the secretsItems is false.
Twitch channel: https://www.twitch.tv/nogard_
My not very used twitter account: https://twitter.com/Nogard__
Clear list: https://goo.gl/rnoqiz

l3agu32

  • Wannabe
  • Posts: 22
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
  • Playstyle: Keyboard
Thank you, Nogard, it worked. I forget that codes can have more details than I think.

L4Vo5

  • Cherry Eater
  • Posts: 59
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 51.0.2704.103 Chrome 51.0.2704.103
    • View Profile
  • Playstyle: Keyboard
Or you could use a for statement. Because if ANY of the values is false the object gets destroyed, this is quite simple:

Code: [Select]
for(i = 0;i<8;i++){
      if global.secretItem[i] == false {
         instance_destroy();
      }
}
I have to admit, i still haven't beaten IWBTG