Skip to content

javascript

mithrendal edited this page Mar 28, 2021 · 19 revisions

scripting complex control of vc64web

pure javascript can be used for more complex control ...

API

function sprite_xpos(0..7) //returns the current x-position of the selected sprite... 
function sprite_ypos(0..7) //returns the current x-position of the selected sprite... 
function not_stopped(this_id) //returns whether a the user asked the script to stop ... 
//set_port_owner gives exclusive control of the port so that signals do not mix   
function set_port_owner(1..2,PORT_ACCESSOR.MANUAL or PORT_ACCESSOR.BOT); returns previous port owner

template for a game loop

//repeats action until action button is pressed again
while(not_stopped(this_id))
{
  //do some action
  await action("A=>500ms"); // presses Keyboard 'A' and waits 500ms
}

example

var x=sprite_xpos(1);

var y=sprite_ypos(1);

while(not_stopped(this_id))

{

  console.log('------'+x + ' '+sprite_xpos(1));

  await my_move_strategy1(1);  

  await my_aim_and_shoot(1);

  console.log('------'+x + ' '+sprite_xpos(1));

}

async function my_move_strategy1(port)

{ 

  await action("j"+port+"right1=>850ms");

  await action("j"+port+"right0=>800ms");

  await action("j"+port+"left1=>450ms");

  await action("j"+port+"left0=>800ms");

}

async function my_aim_and_shoot(port)

{ 

  await action("j"+port+"fire1=>j"+port+"left1");

  await action("300ms");

  await action("j"+port+"left0=>j"+port+"fire0");

}

alert('finished the script');

Clone this wiki locally