GS can't self reference variables?
Backtothis
Member, PRO Posts: 75
On the first loaded actor on a scene, I set the camera values (which remain static throughout the scene), so lets say
self.camera.height = 400
self.camera.width = 300
Now in the command right before using the pause feature (since that messes up the camera), I had
Constrain {self.camera.height = self.camera.height}
Constrain {self.camera.width = self.camera.width}
Under the assumption it would just evaluate the current camera values like I'm used to in every programming language. Curiously this didn't work. But when I did
Constrain {self.camera.height = 400}
Constrain {self.camera.width = 300}
Now the behavior was what I expected. Yet, things like
VariableX = VariableX + VariableY works... so....I'm a bit confused why this happens.
self.camera.height = 400
self.camera.width = 300
Now in the command right before using the pause feature (since that messes up the camera), I had
Constrain {self.camera.height = self.camera.height}
Constrain {self.camera.width = self.camera.width}
Under the assumption it would just evaluate the current camera values like I'm used to in every programming language. Curiously this didn't work. But when I did
Constrain {self.camera.height = 400}
Constrain {self.camera.width = 300}
Now the behavior was what I expected. Yet, things like
VariableX = VariableX + VariableY works... so....I'm a bit confused why this happens.
Comments
So sometimes you need to make workarounds to overcome the lack of "real code"..
As to your subject, once you go into a pause scene, you can't have access to your previous scene from that pause scene, think about it as if the pause scene is a completely different module with access only to its own objects and the game's (global) attributes.
So those 2 constrains you have there, stops constraining once you in pause.
I'd recommend using 2 game variables for the scene height and width and constrain to their values..
Hope that helps
Roy.
Constrain camera size x or y to screen size x or y
Or
Change game.camerawidth to game.scene.camera.width
Then constrain game.scene.camera.width to game.camerawidth
But really what I'm asking about is how Gamesalad parses expressions. In any pass-by-value programming language construct in existence, camera.height = camera.height will be parsed as camera.height = 400. So is Gamesalad pass-by-reference in this case? Because I'm told it's pass-by-value, which makes it rather confusing.
edit - And just to be doubly clear, this question is not about cameras (because I have it working), it's about expression parsing. Specifically it's about something that acts like a pass-by-reference in this case, whereas usually it appears to be pass-by-value, so therein lies my confusion.
If you're using the built-in scene attributes, it's not going to work when you change scenes or pause the game (thereby going to another scene). You'd have to constrain the scene attributes to custom game attributes and then constrain the game attributes however you were doing before. This is basically what @POM was getting at.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@Backtothis To echo what @POM said in a different way, attributes can be seen as containers, and they contain values. So constraining {self.camera.height = self.camera.height}, etc is meaningless as you're just comparing the same containers, not constraining the value in one container to be the value in another container.
So it's not curious really that something like Constrain {self.camera.height = 400} works OK because there's no in-built system there to check if the value given is the same as what's already there, and why should there be...
Hopefully that's helped made clearer a bit of programming logic for you.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps