Don't forget to put your button function into "if(first() | changed(EGP)){}"
Here's a small Touch Screen Tutorial, it should help you:
Code:
@name EGP Touchscreen Tutorial
@inputs EGP:wirelink
@outputs
@persist User:entity Cursor:vector2 Use B
@trigger
##How to use the button() function by Link320
##(Actually it's more of a 'the cursor is over this object' function, it doesn't actually make buttons)
#We need an interval, or runOnTick(1), so that the E2 runs without you changing an input.
interval(100)
if(first() | changed(EGP)){
EGP:egpClear()
#Define the function.
function number wirelink:button(Cursor:vector2,ID:number){
local BPos = This:egpPos(ID)
local BSize = This:egpSize(ID)/2
local Pressed = inrange(Cursor,BPos-BSize,BPos+BSize)
return Pressed
}
#Create the box. This is going to be my button. Its index is 1. We create this before running EGP:button()
EGP:egpBox(1,vec2(256, 180),vec2(128))
EGP:egpBox(2,vec2(256, 350),vec2(128))
}
#Get the person using the screen
User = EGP["User",entity]
#Get the position of their cursor on the screen
Cursor = EGP:egpCursor(User)
#Get whether the person is pressing use
Use = User:keyUse()
#If I press use on the screen...
if(changed(Use) & Use){
if(EGP:button(Cursor,1)){
soundPlay(1,0,"/ancient_button1.wav")
}
elseif(EGP:button(Cursor,2)){
B = !B #Note that B is in persists
Color = B ? vec(200,0,0) : vec(255)
# ^If you haven't come across this before, this is short for "if(B){vec(200,0,0)} else{vec(255)}"
EGP:egpColor(2,Color)
}
}
(17-06-2014, 03:37 PM)_BL4CKH4WK Wrote: Don't forget to put your button function into "if(first() | changed(EGP)){}"
Here's a small Touch Screen Tutorial, it should help you:
Code:
@name EGP Touchscreen Tutorial
@inputs EGP:wirelink
@outputs
@persist User:entity Cursor:vector2 Use B
@trigger
##How to use the button() function by Link320
##(Actually it's more of a 'the cursor is over this object' function, it doesn't actually make buttons)
#We need an interval, or runOnTick(1), so that the E2 runs without you changing an input.
interval(100)
if(first() | changed(EGP)){
EGP:egpClear()
#Define the function.
function number wirelink:button(Cursor:vector2,ID:number){
local BPos = This:egpPos(ID)
local BSize = This:egpSize(ID)/2
local Pressed = inrange(Cursor,BPos-BSize,BPos+BSize)
return Pressed
}
#Create the box. This is going to be my button. Its index is 1. We create this before running EGP:button()
EGP:egpBox(1,vec2(256, 180),vec2(128))
EGP:egpBox(2,vec2(256, 350),vec2(128))
}
#Get the person using the screen
User = EGP["User",entity]
#Get the position of their cursor on the screen
Cursor = EGP:egpCursor(User)
#Get whether the person is pressing use
Use = User:keyUse()
#If I press use on the screen...
if(changed(Use) & Use){
if(EGP:button(Cursor,1)){
soundPlay(1,0,"/ancient_button1.wav")
}
elseif(EGP:button(Cursor,2)){
B = !B #Note that B is in persists
Color = B ? vec(200,0,0) : vec(255)
# ^If you haven't come across this before, this is short for "if(B){vec(200,0,0)} else{vec(255)}"
EGP:egpColor(2,Color)
}
}