Shop OBEX P1 Docs P2 Docs Learn Events
how to transfer two value which inputed through a keyboard to another object? — Parallax Forums

how to transfer two value which inputed through a keyboard to another object?

daniel dingdaniel ding Posts: 52
edited 2011-11-21 18:42 in Propeller 1
hi everyone
I use a keyboard to input two value and put the value I input transfer to another object. what should I do?
thanks

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-11-15 19:32
    Daniel,

    Be patient with me as I am still learning to be patient with those still learning.
    One of the objectives of this forum is to HELP, however that does not mean for every single microstep of the way. Surely you know how to pass values as there are numerous examples in the forum and obex. Have you practiced the examples that are in the Propeller manual? Do this first and make sure you understand it rather than simply by "copy and paste" or whatever anybody else shows you.

    Anyway, the answer to your question is very simple yet you have provided no details whatsoever of the code or the object. Learn to provide details which requires thinking about it which in turn may produce the solution for you,
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-11-15 19:40
    Hi Daniel,

    There are several ways of doing this.

    You can have a parameter in your start method with the address of the variables.

    Your top object would use code like this.
    VAR
      long x, y
    OBJ
      Child: "MyChildObject"
    PUB Main
      Child.Start(@x, @y)
    
      repeat
        ' do stufff that changes the value of x and y
    
    

    The child object would use:
    VAR
      long stack[32]
      word xLocation, yLocation
    PUB Start(xPointer, yPointer)
      xLocation := xPointer
      yLocation := yPointer
      newcog(MainLoop, @stack)
    PUB MainLoop | oldX, oldY, localX, localY
      oldX := 0 ' or some other start value
      oldY := 0
      repeat
        localX := long[xLocation]  
        if localX <> oldX
          ' do stuff that needs to be done when x changes
          oldX := localX ' we use localX incase x in the parent changes
                         ' between the comparison and the time we set want 
                         ' to change the value of oldX
        ' do the same for the y value
    

    Here's another way.
    VAR
      long x, y
    OBJ
      Child: "MyChildObject"
    PUB Main
      Child.Start(x, y)  ' x and y would both be zero
      ' You probably don't need to pass the x and y values with
      ' the start method.
    
      repeat
        ' do stufff that changes the value of x and y
    
        Child.Update(x, y)
    

    The child object would use:
    VAR
      long stack[32]
      long x, y
    PUB Start(localX, localY)
      x := localX  ' You probably don't need to know the x and y values yet.
      y := localY ' The Start method may not need parameters.
      newcog(MainLoop, @stack)
    PUB Update(localX, localY)
      x := localX
      y := localY
    PUB MainLoop | oldX, oldY, localX, localY
      oldX := x + 1 ' just to make sure oldX doesn't equal x
      oldY := y + 1
      repeat
        localX := x ' you probably still want to do this 
        if localX <> oldX
          ' do stuff that needs to be done when x changes
          oldX := localX ' we use localX incase x in the parent changes
                         ' between the comparison and the time we set want 
                         ' to change the value of oldX
        ' do the same for the y value
    

    Those are a couple of ways.

    Both of these examples assume you want the child object to do something when x or y change. If you don't need to monitor for changes, you don't need the variables "oldX" and "oldY".

    Both examples also assume you want a loop in the child object to run in it's own cog. You could have the child object use the same cog as the parent object if it's okay for the parent object to wait for the child object to complete its tasks.

    Edit: Yes to what Peter said, or you might find that someone is it in the mood to type (because it's easier than working on their own project).
  • daniel dingdaniel ding Posts: 52
    edited 2011-11-15 23:13
    Peter
    Thanks your advises, u are wright.
    I will be patient enough to learn more from the propeller manual.
    As you know as a beginner it is really a hard work for a man who is English as a second language.
    Whatever I will work harder and harder to learn it.
    thanks again
    Daniel
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-11-15 23:30
    We just want you to learn and have fun learning plus it saves our keyboards (and hair) from wearing out sooner than expected ;)

    My wife teaches senior science in a high school where English is predominantly the second language and for sure there are difficulties with understanding English let alone the subject. However programming and maths are fairly universal and the concepts are clearly there in the examples such as passing parameters to another function whether it be local or in an "object".
  • daniel dingdaniel ding Posts: 52
    edited 2011-11-21 00:40
    Duane,
    Thanks for your help several days before.
    In my program I want to make a out-time of operation.
    For one if I press the TAB key, the operation will get a out_time and when I press it again it continues.
    I tried (repeat wiatcnt(), pub abort and quit commands but useless)
    can u give me some advises.
    thanks
    Daniel
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-11-21 09:53
    Again .. daniel ... it is against forum rules to post the same question in several threads!!
    For this question you started a new thread.

    Why is it against forum rules?

    Because someone might not know both places when reading it first. Then he answers it, which can take some time and then he figures out that there is already an answer in another thread.

    Please respect the forum rules!
  • daniel dingdaniel ding Posts: 52
    edited 2011-11-21 18:42
    Magl02
    I am so sorry.
    I will respect the rules, I post a question to Duane first.
    Then I thought may be I should post a new thread and get more help from the forum.
    I am sorry.
    Daniel
Sign In or Register to comment.