Click on text?

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Click on text?

Post by coolw »

Is there an easy way to tell if text called by

Code: Select all

Print
was clicked? So if I printed "Yes" and "No" the program could tell which one was clicked, or do I have to set up a virtual click box?

Code: Select all

Text 0,40, "Yes   "+y
    Text 0,80, "No   "+n
    mx=MouseX()
    my=MouseY()
    width1 = TextWidth("Yes")
    height1 = TextHeight("Yes")
    width2 = TextWidth("No")
    height2 = TextHeight("No")
    
    If mx>0 And mx<width1 Then
        If my>40 And my<53 Then y=1
        Else
            y=0
    Else
        If mx>0 And mx<width2 Then
            If my>80 And my<(80+height2) Then n=1
        Else
            n = 0
        EndIf
    EndIf
    
    If y=1 And n=1 Then
        y=0 And n = 0
    EndIf
    
    If MouseDown(1) And y=1 Then
        pwp=1
        Goto Pw
    Else
    If MouseDown(1) And n=1 Then
        pwp=0
        Goto User
    EndIf
    EndIf
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
jarvinen
Newcomer
Posts: 43
Joined: Tue Aug 28, 2007 5:00 pm
Location: Juupajoki/Tampere
Contact:

Re: Click on text?

Post by jarvinen »

Like this?

Code: Select all

Function YesNo(_x, _y)

	Locate _x, _y
	Print "Yes"
	
	Locate _x + TextWidth("Yes") + 10, _y
	Print "No"
	
	If MouseHit(1) And MouseX() > _x And MouseX() < _x + TextWidth("Yes") And MouseY() > _y And MouseY() < _y + TextHeight("Yes") Then
		Return "Yes"
	ElseIf MouseHit(1) And MouseX() > _x + 10 + TextWidth("Yes") And MouseX() < _x + 10 + TextWidth("Yes")  + TextWidth("No") And MouseY() > _y And MouseY() < _y + TextHeight("No") Then
		Return "No"
	Else
		Return 0
	EndIf
	
EndFunction

Repeat

	YesNo(30, 60)
	
	Text x, y, YesNo(30, 60)
	
	If YesNo(30, 60) = "Yes" Then MakeError "Works!"
	
	DrawScreen
Until KeyHit(1)
Down with the clown.
Post Reply