sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Understanding Variables

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 158 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Anton_S
      last edited by

      In classes:
      @var - instance variable
      @@var - class variable

      If those variables would be initialized outside of class(Ex: Sketchy physics ontick attribute: "if frame==0 then @var=0; @@var=0; end"), would there be no difference between those variables anymore?

      Thanks, ant-on

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @anton_s said:

        If those variables would be initialized outside of class...

        Your question makes no sense at all.

        A class variable, by it's nature, is WITHIN a class, and accessible to all instances of that class. It's like a family value, as opposed to a personal (instance var) value or community (global var) value.

        An instance var (@var) is like a personal value. (Thinking of yourself as an instance of class Human,.... how much money YOU have in YOUR pocket, is an instance value.)

        How much money ALL of us humans together have in our pockets, would be a class value.

        And... DONT create @var instance variables, in the global ObjectSpace (at least in plugins that you distribute.)

        Now logically, if your set them both to point at 0, and test them with ==, you will get a true result, but only for as long as they point at the same object. (Remember in Ruby, the set of Integers is "immediate", meaning their is only 1 of each ordinal in the set. EVER.)

        OK? There are NOT two variables, each holding a value of 0.
        There ARE two references, each pointing at the same Ruby object, 0 which is an instance of class Integer, and the only one in the set that equals zero, numerically.

        Ruby has 2 things. Objects and References that point at objects.

        If you keep thinking "variables" instead of "references", your will just frustrate yourself.
        @var = 8
        "The reference @var shall point at the object 8."
        @@var = @var
        "The reference @@var shall point at the object that @var is pointing at."
        @var = 32
        "The reference @var shall be reassigned to point at the object 32."
        In the console:
        @var

        32
        @@var
        8

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Anton_S
          last edited by

          Okay, now I know!! πŸ˜„ And yeah at first my question made sense to me, but now it doesn't!

          Thanks πŸ˜„

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement