Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Help needed to continue this small project

 [1/7] from: gerardcote:sympatico:ca at: 28-Oct-2005 21:58


Hi List, I just began a small robot simulation project to help new people to get acquainted with pseudo-code (robot instructions). I almost finally completed my display but without using VID. Enclosed below is my first version of the code needed to create this display so you can try it for yourself. At this point I asked myself some questions but found only vague answers. So if someone can help It could be useful to me in a near future. 1. Can we design something almost similar using VID and buttons instead of the "robot-cmds" pane with its Forward, Back, Left, Right, Pick and Deliver faces knowing that the first "game-space" panel face has a grid effect (is this possible to translate it under VID?) . The second difficulty I saw to using VID was the precise positioning (in fact everything can be repositioned but this first design seemed realistic enough for me). 2. How can the actual keyboard handler enclosed with the Robot face be transfered into a more central place than inside a specific face as now - it is inside the Robot face since this is what is kept moving - even if this seems logic at first. I read about the Insert-event-func and tried to mimic the Cyphre's way of doing things with his draw-tutor2.r but I can't use it satisfactorily for the moment. Is it the way to go ? From this point on I will work on the display of simple cmds given to the robot and recognition of them by the robot which will translate them into basic operations (Forward, Back, Left and Right plus Pick an object and Deliver it). Any help would be appreciated! Regards, Gerard

 [2/7] from: carl:cybercraft at: 5-Nov-2005 19:50


Hi Gerard, Did you attach your code to the email? As attachements are stripped out with this list. If so, just include it in the body of the email for us to be able to see it. -- Carl Read. On Friday, 28-October-2005 at 21:58:41 Gerard Cote wrote,

 [3/7] from: gerardcote:sympatico:ca at: 28-Oct-2005 22:13


Sorry for the missing file. Here it is. Gerard -- Binary/unsupported file stripped by Ecartis -- -- Type: text/x-rebol -- File: Move with keys-mod-6a.r

 [4/7] from: tom:conlin::gmail at: 28-Oct-2005 22:28


Hi Gerald, The rebol list does not accept attachments just paste the code into the message body. On 10/28/05, Gerard Cote <gerardcote-sympatico.ca> wrote:
> Sorry for the missing file. > Here it is.
<<quoted lines omitted: 5>>
> To unsubscribe from the list, just send an email to > lists at rebol.com <http://rebol.com> with unsubscribe as the subject.
-- ... nice weather eh

 [5/7] from: gerardcote::sympatico::ca at: 29-Oct-2005 17:43


Finally it seems that I must include my code right here! Regards, Gerard REBOL [ ] ; This is a simple test to define a button-like face - It works butn: load-thru/binary http://www.rebol.com/how-to/graphics/button.gif btn-face: make face [ edge: none color: none image: butn ] ; End of test code game-space: make face [ offset: 50x50 size: 700x450 edge: none effect: reduce [ 'grid 50x50 0x0 2x2 0.200.0] color: water pane: reduce [ Robot: make face [ text: "I am the robot" font: make font [align: 'left] size: 50x50 center: 25x25 offset: 50x50 color: gold edge: none feel: make feel [ engage: func [face action event] [ if action = 'key [ print ["Key: " event/key] ; Détection des touches alphabétiques (Alphabetic keys detection) if any [all [event/key >= #"a" event/key <= #"z"] all [event/key >= #"a" event/key <= #"z"]][ if any [event/key = #"f" event/key = #"F"][ face/text: offset if offset/y >= 100 [offset: offset - 0x50] ] if any [event/key = #"b" event/key = #"B"][ face/text: offset if offset/y <= (game-space/size/y - 250) [offset: offset + 0x50] ] if any [event/key = #"l" event/key = #"L"][ face/text: offset if offset/x >= 100 [offset: offset - 50x0] ] if any [event/key = #"r" event/key = #"R"][ face/text: offset if offset/x <= (game-space/size/x - 250) [offset: offset + 50x0] ] ] ; Détection des touches fléchées (Arrows detection) switch/default event/key [ up [face/text: offset if offset/y >= 100 [offset: offset - 0x50]] down [face/text: offset if offset/y <= (game-space/size/y - 250) [offset: offset + 0x50]] left [face/text: offset if offset/x >= 100 [offset: offset - 50x0]] right [face/text: offset if offset/x <= (game-space/size/x - 250) [offset: offset + 50x0]] bs [remove back tail face/text] cr [unview] escape [unview] ][ face/text: event/key ] ;show robot-cmds ; Test code for num keys to write in robot-cmds panel instead of Robot face ; Détection des touches numériques ;if all [event/key >= #"0" event/key <= #"9"] [ ; system/view/focal-face: robot-cmds ; system/view/caret: tail robot-cmds/text ; ;clear head robot-cmds/text ; append robot-cmds/text event/key ; show robot-cmds ; system/view/focal-face: Robot ; system/view/caret: tail Robot/text ; ;system/view/caret: tail face/text ;] ; End of test code show Robot ];if ];engage ];feel ];Robot face Command-panel: make face [ text: "" font: make font [align: 'left] offset: 0x300 size: 550x150 color: white edge: none pane: reduce [ legend: make face [ text: "- - Legend - -" font: make font [align: 'center] offset: 20x10 size: 100x160 color: silver edge: none ] legend-1: make face [ text: "Robot" font: make font [align: 'center] offset: 30x45 size: 80x20 color: gold edge: none ] legend-2: make face [ text: "Start pos" font: make font [align: 'center] offset: 30x70 size: 80x20 color: white edge: none ] legend-3: make face [ text: "Stop pos" font: make font [align: 'center] offset: 30x95 size: 80x20 color: brown edge: none ] legend-4: make face [ text: "Pick up item" font: make font [align: 'center] offset: 30x120 size: 80x20 color: gray edge: none ] robot-cmds: make face [ text: "- - ROBOT COMMANDS - -" font: make font [align: 'center] offset: 190x10 size: 160x160 color: silver edge: none ] robot-cmds-1: make face [ text: "(F)orward" font: make font [align: 'center] offset: 240x40 size: 60x20 color: red edge: none ] ; Another part for the test of a button ; Image d'un bouton rouge sur fond blanc ;make btn-face [ ; text: "(F)orward" ; font: make font [align: 'center] ; offset: 240x40 ; size: 60x30 ; effect: [fit] ;] ; End of this test part robot-cmds-2: make face [ text: "(B)ack" font: make font [align: 'center] offset: 240x80 size: 60x20 color: red edge: none ] robot-cmds-3: make face [ text: "(L)eft" font: make font [align: 'center] offset: 190x60 size: 45x20 color: red edge: none ] robot-cmds-4: make face [ text: "(R)ight" font: make font [align: 'center] offset: 305x60 size: 45x20 color: red edge: none ] robot-cmds-5: make face [ text: "(P)ick" font: make font [align: 'center] offset: 200x120 size: 60x20 color: red edge: none ] robot-cmds-6: make face [ text: "(D)eliver" font: make font [align: 'center] offset: 285x120 size: 60x20 color: red edge: none ] ] ] Program-zone: make face [ text: "Here will appear the program." font: make font [align: 'left] offset: 550x0 size: 150x550 color: red edge: none ] ] ] ; This permits to write text inside ROBOT face system/view/focal-face: Robot system/view/caret: tail Robot/text view game-space

 [6/7] from: antonr:lexicon at: 1-Nov-2005 0:36


Hi Gerard, Happily, everything you ask for is possible. See bottom for a partial VID conversion of your robot control script. Here are some additional tips: I noticed much similarity in the legend faces, so you can save a lot of code by using an existing face object as a prototype, eg: legend-2: make legend-1 [ text: "Start pos" ;font: make font [align: 'center] ; <-- this is the same offset: 30x70 size: 80x20 color: white ;edge: none ; <-- this is the same ] So you don't have to begin with a simple face every time. Now, converting to VID. The way to MAKE from the standard face inside the layout dialect: view layout [ face with [ init: [] size: 0x0 ] ] That is the bare minimum. You must specify at least INIT and SIZE or there is an error. You can use FACE because it is in this list: extract svv/vid-styles 2 ;== [face blank-face IMAGE BACKDROP BACKTILE BOX Now, back to the Legend. You can use STYLE to create your own styles for use in your layout specification block. layout [ style legend box 80x20 gray "legend" font [size: 14 color: black shadow: 0x0] top legend-1: legend gold "Robot" legend-2: legend white "Start Pos" ] Here I found a style similar to what I want - BOX. (Is it really ? I had to modify the font etc.. Perhaps there is another style that is better, perhaps TXT ?) So the above has created a LEGEND style that is a BOX with all the modified facets in it by default. Now I can use the LEGEND style several times, and I only have to specify the changing parts. Key handling. You should look at the default window key handler first before you make your own: view/new window: layout [] unview probe window/feel You can see how it looks for subfaces which can handle the key event and delegates to them. I often just blow away the default key handler for programs like this. view/new window: layout [] window/feel: make window/feel [ detect: func [face event][ if event/type = 'key [ ;... ] event ; allow event to continue ] ] do-events You must allow some event types to continue, like the 'close event, otherwise the window close gadget will not respond. I often just let all the events continue, even if I am handling some of them, like the key events here. I never really bothered with INSERT-EVENT-FUNC. I always got what I wanted using the above technique (which seems to be less abstract), but insert-event-func might be good for a situation with multiple windows, or maybe saving a few keystrokes. I hope this was useful. (see script at bottom) Regards, Anton.
> Hi List, > I just began a small robot simulation project to help new people
<<quoted lines omitted: 26>>
> Regards, > Gerard
rebol [ Title: "robot2" File: %robot2.r Date: 31-Oct-2005 Version: 1.0.0 Progress: 0.0 Status: "working" Needs: [View] Author: "Anton Rolls" Language: "English" Purpose: {example conversion to VID of Gerard Cote's robot script} Usage: {} History: [ 1.0.0 [31-Oct-2005 {First version} "Anton"] ] ToDo: { - } Notes: {} ] view/new window: center-face layout [ size 700x450 + 2x2 ; 2x2 for right/bottom gridline backeffect [grid 50x50 0x0 2x2 0.200.0] backcolor water origin 0 space 0 at 50x50 robot: txt 50x50 black gold at 0x300 panel 550x150 effect [merge luma -20] [ ; <-- command panel ; LEGEND at 20x10 panel 100x130 effect [merge luma -20] font-size 14 "- Legend -" top [ pad 10x24 ; leave some room for the panel text style legend box 80x20 font [color: black shadow: 0x0] legend gold "Robot" legend white "Start Pos" ] ; ROBOT COMMANDS at 240x10 panel 250x130 effect [merge luma -20] font-size 14 "- Robot Commands -" top [ pad 10x24 ;button "Up" ;<-- you could use BTN BUTTON or just BOX ] ] at 550x25 panel 150x400 effect [merge colorize 210.80.80] "Here will be the program" [ origin 20x20 btn "Begin" ] ] move: func [offset [pair!]][ robot/offset: robot/offset + offset ; limit to play area robot/offset: min max robot/offset (0x0) (window/size - robot/size - 2x2 - 100x100) show robot ] ; Here is a window global key handler, if you want to do it this way window/feel: make window/feel [ detect: func [face event /local key][ if event/type = 'key [ ;if char? key: event/key [key: uppercase key] key: event/key case [ find [#"L" #"l" left ] key [move -50x0] find [#"R" #"r" right] key [move 50x0] find [#"U" #"u" up ] key [move 0x-50] find [#"D" #"d" down ] key [move 0x50] ] ] event ; allow the event to continue ] ] do-events

 [7/7] from: gerardcote::sympatico::ca at: 31-Oct-2005 21:00


Thank you Anton, I'll try to do my best with your information. Seems comprehensive enough but I have to digest the switch before I can forge a real opinion about the process. Regards, Gerard

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted