loading
 
VBScript to Keyboard Send
Ben from United States  [4 posts]
6 years
I am trying to make a usb missile launcher follow a red blob and then shoot it when it centers on it. (see attached) I am using the Keyboard_Send module to send a left or a right keyboard arrow to the missile launcher program.

The only part that does not work is reassigning a different value to the "key_ to_send" variable each time I move the blob.   For instance when I move the blob to the left and test <=100, "key_to_send" is still shows up as equal to {RIGHT} (under the modified Variable table in VBScript module) instead of {LEFT}. So the missile launcher continues to turn right.

Let me know if you have any advice.



Here is the VBScript I am using( I have attached the .robo file I am using):


cogx = GetVariable("COG_X")
leftThreshold = 100
rightThreshold = 200

SetVariable "test", cogx

if test <= leftThreshold then
  SetVariable "key_to_send", "{LEFT}"
else
  if test >= rightThreshold then
  SetVariable "key_to_send", "{RIGHT}"
  else
    SetVariable "key_to_send", ""
  end if
end if

cogx = GetVariable("COG_X")
leftThreshold = 100
rightThreshold = 200

SetVariable "test", cogx

if test <= leftThreshold then
  SetVariable "key_to_send", "{LEFT}"
else
  if test >= rightThreshold then
  SetVariable "key_to_send", "{RIGHT}"
  else
    SetVariable "key_to_send", ""
  end if
end if


 

program.robo
Ben from United States  [4 posts] 6 years
I copied the code twice above, it should just be:

cogx = GetVariable("COG_X")
leftThreshold = 100
rightThreshold = 200

SetVariable "test", cogx

if test <= leftThreshold then
  SetVariable "key_to_send", "{LEFT}"
else
  if test >= rightThreshold then
  SetVariable "key_to_send", "{RIGHT}"
  else
    SetVariable "key_to_send", ""
  end if
end if
Anonymous 6 years
Answered here

http://www.roborealm.com/forum/index.php?thread_id=4017#

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index