Post Reply 
Visual Basic, omg
i learned vb 4 years ago and i'm learning everything again
Author Message
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #1
Visual Basic, omg
Ok I'm making a program that has 3 games, everything is ok, it's in portuguese, so i will translate from PT to EN

in this game, I've 3 images: jessica_mini, mensagem and mensagem2
in this game, I've 1 label: mensagens_lidas_label, it shows the number of messages taken by the player

mensagem means message

this isn't working:
        Dim showMS1 As Integer
        Dim showMS2 As Integer
        Dim mensagens_lidas As Integer
        mensagens_lidas = 0
        showMS1 = 1
        showMS2 = 1
        If showMS1 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem.Bounds) Then
                MsgBox("la la la")
                mensagem.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagens_lidas_label.Text = mensagens_lidas
                showMS1 = 0
            End If
        End If

        If showMS2 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem2.Bounds) Then
                MsgBox("la la la")
                mensagem2.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagens_lidas_label.Text = mensagens_lidas
                showMS2 = 0
            End If
        End If

what that should do is:
when the player(jessica_mini) touches the mensagem image, a message box appears » working
when the player(jessica_mini) touches the mensagem2 image, a message box appears » working
the images (mensagem and mensagem2 hide after being touched » working
the label mensagens_lidas_label shows the number of messages taken by the player » it shows 1 after i take the first message but it doesn't show 2 when i take the 2 messages i don't know why

the action jessica_mini.Bounds.IntersectsWith(mensagem2.Bounds) should just be executed when showMSG2 or showMS1 are iqual to 1, but after i say showMSG1/showMSG2 are iqual to 0, the action, still be executed.

17/11/2007 04:58 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,023.4213
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.0333
Offline
Post: #2
RE: Visual Basic, omg
I'm guessing the variable mensagens_lidas is declared locally.  For all languages (that I know of) local variables loose their value after the function ends.  Either declare it as Static, or declare it globally.
(This post was last modified: 17/11/2007 05:58 AM by ZiNgA BuRgA.)
17/11/2007 05:58 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #3
RE: Visual Basic, omg
the variable is declared as static, it isn't on that copy pasted code.

EDIT, mensagens_lidas means read_messages

i fixed this problem:
Quote:the action jessica_mini.Bounds.IntersectsWith(mensagem2.Bounds) should just be executed when showMSG2 or showMS1 are iqual to 1, but after i say showMSG1/showMSG2 are iqual to 0, the action, still be executed.
i just need to fix the label problem, it shows 1 and doesn't change from one after i take the other message... =|

(This post was last modified: 17/11/2007 12:34 PM by Pirata Nervo.)
17/11/2007 11:59 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Anger
Angered Observer (0).(0)

Posts: 605.8490
Threads: 4
Joined: 14th Apr 2007
Reputation: 1.65651
E-Pigs: 5.4993
Offline
Post: #4
RE: Visual Basic, omg
showMS1 = 1
        showMS2 = 1

umm there being set to 1 and then there being checked - there always going to be 1 because each time you run that function it sets them to 1. maybe you meant to make em 0 outside the function.

Always remember - Google is your friend :)

[Image: avatar_416_482669e4.jpg]
17/11/2007 03:01 PM
Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #5
RE: Visual Basic, omg
but i can't set values outside the function =|

as i said, i already fixed that problem.

i need help with the label now.

EDIT, fixed!

(This post was last modified: 18/11/2007 02:47 AM by Pirata Nervo.)
18/11/2007 02:44 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Anger
Angered Observer (0).(0)

Posts: 605.8490
Threads: 4
Joined: 14th Apr 2007
Reputation: 1.65651
E-Pigs: 5.4993
Offline
Post: #6
RE: Visual Basic, omg
o you fixed it - what was wrong?

Always remember - Google is your friend :)

[Image: avatar_416_482669e4.jpg]
18/11/2007 06:26 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #7
RE: Visual Basic, omg
This is my code now:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Public Class Form3
    Public mensagens_lidas As String
    Dim showMS1 As Integer
    Dim showMS2 As Integer

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        showMS1 = 1
        showMS2 = 1
    End Sub

    Private Sub Form3_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

        Dim jessica_miniRight As Integer
        Dim jessica_miniBottom As Integer
        Dim jessica_miniTop As Integer
        Dim jessica_miniLeft As Integer
        jessica_miniTop = jessica_mini.Top
        jessica_miniLeft = jessica_mini.Left
        jessica_miniRight = jessica_mini.Left + jessica_mini.Width
        jessica_miniBottom = jessica_mini.Top + jessica_mini.Height

        Dim diogo_miniRight As Integer
        Dim diogo_miniBottom As Integer
        Dim diogo_miniTop As Integer
        Dim diogo_miniLeft As Integer
        diogo_miniTop = diogo_mini.Top
        diogo_miniLeft = diogo_mini.Left
        diogo_miniRight = diogo_mini.Left + jessica_mini.Width
        diogo_miniBottom = diogo_mini.Top + jessica_mini.Height

        If e.KeyCode = Keys.Up Then
            jessica_mini.Top = jessica_mini.Top - 10
            diogo_mini.Top = diogo_mini.Top - 14
            diogo_mini.Left = diogo_mini.Left - 14
        End If
        If e.KeyCode = Keys.Down Then
            jessica_mini.Top = jessica_mini.Top + 10
            diogo_mini.Top = diogo_mini.Top + 14
            diogo_mini.Left = diogo_mini.Left + 14
        End If
        If e.KeyCode = Keys.Left Then
            jessica_mini.Left = jessica_mini.Left - 10
            diogo_mini.Left = diogo_mini.Left - 14
            diogo_mini.Top = diogo_mini.Top - 14
        End If
        If e.KeyCode = Keys.Right Then
            jessica_mini.Left = jessica_mini.Left + 10
            diogo_mini.Left = diogo_mini.Left + 14
            diogo_mini.Top = diogo_mini.Top + 14
        End If

        If jessica_mini.Left <= 0 Then
            jessica_mini.Left = 0
        End If
        If jessica_mini.Left >= 424 Then
            jessica_mini.Left = 424
        End If
        If jessica_mini.Top <= 0 Then
            jessica_mini.Top = 0
        End If
        If jessica_mini.Top >= 420 Then
            jessica_mini.Top = 420
        End If

        If diogo_mini.Left <= 0 Then
            diogo_mini.Left = 423
        End If
        If diogo_mini.Left >= 424 Then
            diogo_mini.Left = 1
        End If
        If diogo_mini.Top <= 0 Then
            diogo_mini.Top = 419
        End If
        If diogo_mini.Top >= 420 Then
            diogo_mini.Top = 1
        End If

        If jessica_mini.Bounds.IntersectsWith(diogo_mini.Bounds) Then
            MsgBox("Ganhaste! Comeste o Diogo! Clica Ok para leres a mensagem deixada pelo Diogo")
            MsgBox("Agora que me comeste (ih ih xP), clica OK para passares para o próximo nível.")
            diogo_mini.Hide()
            mensagem.Hide()
            mensagem2.Hide()
            objectivo.Text = "O teu objectivo neste 2º jogo, e' apanhares o maior número possível de Diogos, n te esqueças de apanhar as mensagens!"
            showMS1 = 0
            showMS2 = 0
            jessica_mini.Left = 220
            jessica_mini.Top = 400
            diogo_mini.Left = 100
            diogo_mini.Top = 0
            Form4.Show()
            Me.Hide()
        End If

        If showMS1 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem.Bounds) Then
                MsgBox("Amoro.te muito amor!!! És mt importante para mim. Clica Ok para continuares o jogo.")
                mensagem.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagesn_lidas_label.Text = mensagens_lidas
                showMS1 = 0
            End If
        End If

        If showMS2 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem2.Bounds) Then
                MsgBox("Tu já sabes isto de cor, mas eu vou repetir: ÉS LINDA! xP e quero tar contigo!")
                mensagem2.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagesn_lidas_label.Text = mensagens_lidas
                showMS2 = 0
            End If
        End If

    End Sub

End Class


before: (and something that i can't remember what i changed.)

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Public Class Form3
    Public mensagens_lidas As String
    Dim showMS1 As Integer
    Dim showMS2 As Integer

    Private Sub Form3_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

        showMS1 = 1
        showMS2 = 1
        Dim jessica_miniRight As Integer
        Dim jessica_miniBottom As Integer
        Dim jessica_miniTop As Integer
        Dim jessica_miniLeft As Integer
        jessica_miniTop = jessica_mini.Top
        jessica_miniLeft = jessica_mini.Left
        jessica_miniRight = jessica_mini.Left + jessica_mini.Width
        jessica_miniBottom = jessica_mini.Top + jessica_mini.Height

        Dim diogo_miniRight As Integer
        Dim diogo_miniBottom As Integer
        Dim diogo_miniTop As Integer
        Dim diogo_miniLeft As Integer
        diogo_miniTop = diogo_mini.Top
        diogo_miniLeft = diogo_mini.Left
        diogo_miniRight = diogo_mini.Left + jessica_mini.Width
        diogo_miniBottom = diogo_mini.Top + jessica_mini.Height

        If e.KeyCode = Keys.Up Then
            jessica_mini.Top = jessica_mini.Top - 10
            diogo_mini.Top = diogo_mini.Top - 14
            diogo_mini.Left = diogo_mini.Left - 14
        End If
        If e.KeyCode = Keys.Down Then
            jessica_mini.Top = jessica_mini.Top + 10
            diogo_mini.Top = diogo_mini.Top + 14
            diogo_mini.Left = diogo_mini.Left + 14
        End If
        If e.KeyCode = Keys.Left Then
            jessica_mini.Left = jessica_mini.Left - 10
            diogo_mini.Left = diogo_mini.Left - 14
            diogo_mini.Top = diogo_mini.Top - 14
        End If
        If e.KeyCode = Keys.Right Then
            jessica_mini.Left = jessica_mini.Left + 10
            diogo_mini.Left = diogo_mini.Left + 14
            diogo_mini.Top = diogo_mini.Top + 14
        End If

        If jessica_mini.Left <= 0 Then
            jessica_mini.Left = 0
        End If
        If jessica_mini.Left >= 424 Then
            jessica_mini.Left = 424
        End If
        If jessica_mini.Top <= 0 Then
            jessica_mini.Top = 0
        End If
        If jessica_mini.Top >= 420 Then
            jessica_mini.Top = 420
        End If

        If diogo_mini.Left <= 0 Then
            diogo_mini.Left = 423
        End If
        If diogo_mini.Left >= 424 Then
            diogo_mini.Left = 1
        End If
        If diogo_mini.Top <= 0 Then
            diogo_mini.Top = 419
        End If
        If diogo_mini.Top >= 420 Then
            diogo_mini.Top = 1
        End If

        If jessica_mini.Bounds.IntersectsWith(diogo_mini.Bounds) Then
            MsgBox("Ganhaste! Comeste o Diogo! Clica Ok para leres a mensagem deixada pelo Diogo")
            MsgBox("Agora que me comeste (ih ih xP), clica OK para passares para o próximo nível.")
            diogo_mini.Hide()
            mensagem.Hide()
            mensagem2.Hide()
            objectivo.Text = "O teu objectivo neste 2º jogo, e' apanhares o maior número possível de Diogos, n te esqueças de apanhar as mensagens!"
            showMS1 = 0
            showMS2 = 0
            jessica_mini.Left = 220
            jessica_mini.Top = 400
            diogo_mini.Left = 100
            diogo_mini.Top = 0
            Form4.Show()
            Me.Hide()
        End If

        If showMS1 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem.Bounds) Then
                MsgBox("Amoro.te muito amor!!! És mt importante para mim. Clica Ok para continuares o jogo.")
                mensagem.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagesn_lidas_label.Text = mensagens_lidas
                showMS1 = 0
            End If
        End If

        If showMS2 = 1 Then
            If jessica_mini.Bounds.IntersectsWith(mensagem2.Bounds) Then
                MsgBox("Tu já sabes isto de cor, mas eu vou repetir: ÉS LINDA! xP e quero tar contigo!")
                mensagem2.Hide()
                mensagens_lidas = mensagens_lidas + 1
                mensagesn_lidas_label.Text = mensagens_lidas
                showMS2 = 0
            End If
        End If

    End Sub

End Class


18/11/2007 07:18 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Anger
Angered Observer (0).(0)

Posts: 605.8490
Threads: 4
Joined: 14th Apr 2007
Reputation: 1.65651
E-Pigs: 5.4993
Offline
Post: #8
RE: Visual Basic, omg
yeah you moved the showms ones into the form load function (good idea).
i don't see that much difference really but i would have to go through it in detail. but anyway glad it worked out and thanks for sharing. :)

Always remember - Google is your friend :)

[Image: avatar_416_482669e4.jpg]
18/11/2007 01:18 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: