Why doesn't this code work?

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Why doesn't this code work?

Postby juhuwoorps » Sat Jun 26, 2010 11:15 pm

I want to change pictures between 2 hotspots with this code:

Code: Select all
sub change (hsnr)
If parts=0 Then
firstselected=hsnr
parts=parts+1
hsnr=0
Exit Sub
End If


If parts=1 Then
parts=0
secondselected=hsnr


Action.LoadAPicture Hotspot(secondselected), "homer_" & firstselected &".jpg"
Action.LoadAPicture Hotspot(firstselected), "homer_" & secondselected &".jpg"


End If
hsnr=0
firstselected=0
secondselected=0



End Sub


if I try it the first one it works as it should, but at the next time it doesnt work. I dont have error messages, but the pictures doesnt change.

Hope there is someone who could help me with this.

I have tried out a lot, but its always the same.


TiA juhu
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby reneuend » Sun Jun 27, 2010 7:24 pm

I think its because you are "exit sub" in the first routine without resetting some of the variables. But, there are some improvements that could be made.
Instead of incrementing Parts, just set it to 1 or 0. Is parts declared outside of this routine? if not, then that would be a problem also, I would suggest passing it in as a parameter.

Code: Select all
sub change (hsnr, parts)

If parts=0 Then
  firstselected=hsnr
  secondselected= <some value>
  parts=1
  hsnr=0
else
  parts=0
  secondselected=hsnr
  firstselected = <some value>
  Action.LoadAPicture Hotspot(secondselected), "homer_" & firstselected &".jpg"
  Action.LoadAPicture Hotspot(firstselected), "homer_" & secondselected &".jpg"
End If

hsnr=0
firstselected=0
secondselected=0

End Sub
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron