GS can't self reference variables?

BacktothisBacktothis 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.

Comments

  • POMPOM Member Posts: 2,599
    I don't think anything in GameSalad is possible to use by reference, I believe every method is transferring data by value.
    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.
  • BacktothisBacktothis Member, PRO Posts: 75
    Yes, that's what I have right now. The thing is, I only intended for pass by value. I had assumed that by saying [constrain] camera.height = camera.height, that it would substitute the value of camera.height at the moment of running, which would've been 400 (it only changes on the pause screen itself, and this is done before we execute the pause behavior). So I expected that the statement would have been evaluated as camera.height = 400. But it isn't. That's not pass by reference I don't think?
  • joshiwujoshiwu Member Posts: 207
    Kind of stupid to think constrain screen size to itself would have an effect. Try this, it might let some of the stupid out of your skull.
    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


  • joshiwujoshiwu Member Posts: 207
    edited March 2014
    You see camera size is a dynamic attribute that is already got a constrain on it. It's actually very simple. And why is your camera so small? Are you sure you're not thinking of camera origin?
  • BacktothisBacktothis Member, PRO Posts: 75
    I don't really understand what you are saying. Yes I know camera size is dynamic. But also the pause feature resets the previous camera settings, so if I don't constrain them on the previous scene, what happens is the camera is messed up after returning from pause.

    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.
  • BacktothisBacktothis Member, PRO Posts: 75
    edited March 2014
    You see camera size is a dynamic attribute that is already got a constrain on it. It's actually very simple. And why is your camera so small? Are you sure you're not thinking of camera origin?
    I just gave a random value for camera to illustrate my question. Camera origin is also constrained since that also gets reset after coming back from a pause, but my question was more about how expressions are parsed so I just used a toy value for the camera.height.

    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.
  • BacktothisBacktothis Member, PRO Posts: 75
    Actually, the constrain condition wouldn't happen to be repeating itself in the old scene while the pause scene is active would it? That would actually make sense now lol, as I was re-reading what POM said.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I can see the next bumpersticker already running off the presses:
    Try this, it might let some of the stupid out of your skull.
    Just to be clear since you keep mentioning camera.height and camera.width... are those game attributes? Or are they scene attributes? It helps if you include the prefix when you mention attributes.

    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

  • BacktothisBacktothis Member, PRO Posts: 75
    Yes they are scene attributes, and I started realizing that when I read back over his stuff.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2014

    @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

  • BacktothisBacktothis Member, PRO Posts: 75
    Lol for some reason I was thinking of Constrain as an assignment ~_~. Too used to seeing == for equivalence comparison haha. Well that is quite silly of me!
Sign In or Register to comment.