Anonymous user
AGS Pointers for Dummies: Difference between revisions
→Optional Parameters
Line 210: | Line 210: | ||
''Okay, that's nice, but how does it apply to pointers? I tried assigning my Character* parameter a default value and it didn't work.'' | ''Okay, that's nice, but how does it apply to pointers? I tried assigning my Character* parameter a default value and it didn't work.'' | ||
AGS doesn't currently allow you to assign non-integer default values. This means that to make a parameter optional we will have to give it an integer value. But what integer value can we use with pointers? Remember how I mentioned before that '''null''' is equivalent to 0? In most cases you should | AGS doesn't currently allow you to assign non-integer default values. This means that to make a parameter optional we will have to give it an integer value. But what integer value can we use with pointers? Remember how I mentioned before that '''null''' is equivalent to 0? In most cases you should use null to check for null pointers instead of using 0, however, you can't assign a pointer a default value of null. You ''can'' however set a default value of 0. | ||
This does of course mean that you would have to have some means of handling null values for that parameter. Perhaps, for a Character*, it could default to the player character. You could do this by checking your parameter, and if it is null, reassigning it to the player character: | This does of course mean that you would have to have some means of handling null values for that parameter. Perhaps, for a Character*, it could default to the player character. You could do this by checking your parameter, and if it is null, reassigning it to the player character: |