Picture associated with a hotspot random

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

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

Picture associated with a hotspot random

Postby lisbonsasori » Mon May 03, 2010 4:19 am

Can I make the picture associated with a hotspot random from a set of pictures each time a frame loads?
This is needed to create a card game I am working at.
A solution to this problem would be very much appreciated.
Please help me!
lisbonsasori
New Member
 
Posts: 5
Joined: Sun May 02, 2010 7:35 pm

Postby Mystery » Tue May 04, 2010 8:06 pm

Welcome to the forums lisbonsasori :)

You could use something like this:
Code: Select all
randomize
i = int( RND * number_of_total_images ) + 1
if i = 1 Then Action.LoadAPicture Hotspot(HOTSPOT_NUMBER), "FILENAME1"
if i = 2 Then Action.LoadAPicture Hotspot(HOTSPOT_NUMBER), "FILENAME2"
if i = 3 Then Action.LoadAPicture Hotspot(HOTSPOT_NUMBER), "FILENAME3"
...  etc. until last image name is reached


Here is some info about the randomization:
http://www.adventuremaker.com/help/vbsc ... m_variable
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby lisbonsasori » Wed May 05, 2010 4:42 pm

Thank you for your replay, but I did not made myself clear in my question? my bad! LOL

What I needed was to make the pictures associated with the hotspots random from a set of pictures each time a frame loads, without ever repeating the same picture, because there is no repeated card in a card deck?

Fortunately and very, very luckily I was able to solve this problem since I posted my question. It took some work experimenting with the vbscript but I managed to find a way to make it work.

If someone needs to create the same effect, and does not know how, I will post a detailed explanation here. Just ask me for it.
lisbonsasori
New Member
 
Posts: 5
Joined: Sun May 02, 2010 7:35 pm

Postby juhuwoorps » Wed May 05, 2010 5:26 pm

I don't need it at the moment,but I'm curios how you make it work.
:)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby Lyberodoggy » Thu May 06, 2010 8:50 am

I've worked on this kind of randomization before and what I 've learned can be summed in this little example of a lottery:


Code: Select all
dim selected(5)
dim counter
dim numbers(45)
for i=0 to 44
   numbers(i)=i+1
next
do while counter<5
   sel=false
   randomize
   rand=int(rnd*45)+1
   for i=0 to 4
      if selected(i)=rand then
         sel=true
      end if
   next
   if sel=false then
      selected(counter)=rand
      'numbers(rand-1)=0
      counter=counter+1
   end if
loop
for i=0 to 44
   if i mod 5 = 0 then
      text=text+vbcrlf
   end if
   text=text+cstr(numbers(i))+vbtab
next
text=text+vbcrlf+"Selected numbers: "
for i=0 to 4
   text=text+cstr(selected(i))+", "
next
msgbox text,vbokonly,"Joker"
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby lisbonsasori » Thu May 06, 2010 3:02 pm

Let?s say I have a set of 10 pictures and I need to associate 4 to hotspots randomly and without repeating when a frame loads?

This goes into Project Menu, VBS Procedures:
Code: Select all
Sub SpotA
   randomize
   i = int( RND * 10 ) + 1
   a = i

   if a = 1 then Action.LoadAPicture Hotspot(1), "1.jpg"
   if a = 2 then Action.LoadAPicture Hotspot(1), "2.jpg"
   if a = 3 then Action.LoadAPicture Hotspot(1), "3.jpg"
   if a = 4 then Action.LoadAPicture Hotspot(1), "4.jpg"
   if a = 5 then Action.LoadAPicture Hotspot(1), "5.jpg"
   if a = 6 then Action.LoadAPicture Hotspot(1), "6.jpg"
   if a = 7 then Action.LoadAPicture Hotspot(1), "7.jpg"
   if a = 8 then Action.LoadAPicture Hotspot(1), "8.jpg"
   if a = 9 then Action.LoadAPicture Hotspot(1), "9.jpg"
   if a = 10 then Action.LoadAPicture Hotspot(1), "10.jpg"

End Sub

Sub SpotB
   Do Until i <> a
      randomize
      i = int( RND * 10 ) + 1
   Loop

   b = i
   if b = 1 then Action.LoadAPicture Hotspot(2), "1.jpg"
   if b = 2 then Action.LoadAPicture Hotspot(2), "2.jpg"
   if b = 3 then Action.LoadAPicture Hotspot(2), "3.jpg"
   if b = 4 then Action.LoadAPicture Hotspot(2), "4.jpg"
   if b = 5 then Action.LoadAPicture Hotspot(2), "5.jpg"
   if b = 6 then Action.LoadAPicture Hotspot(2), "6.jpg"
   if b = 7 then Action.LoadAPicture Hotspot(2), "7.jpg"
   if b = 8 then Action.LoadAPicture Hotspot(2), "8.jpg"
   if b = 9 then Action.LoadAPicture Hotspot(2), "9.jpg"
   if b = 10 then Action.LoadAPicture Hotspot(2), "10.jpg"

End Sub

Sub SpotC
   Do Until i <> a and i <> b
      randomize
      i = int( RND * 10 ) + 1
   Loop

   c = i
   if c = 1 then Action.LoadAPicture Hotspot(3), "1.jpg"
   if c = 2 then Action.LoadAPicture Hotspot(3), "2.jpg"
   if c = 3 then Action.LoadAPicture Hotspot(3), "3.jpg"
   if c = 4 then Action.LoadAPicture Hotspot(3), "4.jpg"
   if c = 5 then Action.LoadAPicture Hotspot(3), "5.jpg"
   if c = 6 then Action.LoadAPicture Hotspot(3), "6.jpg"
   if c = 7 then Action.LoadAPicture Hotspot(3), "7.jpg"
   if c = 8 then Action.LoadAPicture Hotspot(3), "8.jpg"
   if c = 9 then Action.LoadAPicture Hotspot(3), "9.jpg"
   if c = 10 then Action.LoadAPicture Hotspot(3), "10.jpg"

End Sub

Sub SpotD
   Do Until i <> a and i <> b and i <> c
      randomize
      i = int( RND * 10 ) + 1
   Loop

   d = i
   if d = 1 then Action.LoadAPicture Hotspot(4), "1.jpg"
   if d = 2 then Action.LoadAPicture Hotspot(4), "2.jpg"
   if d = 3 then Action.LoadAPicture Hotspot(4), "3.jpg"
   if d = 4 then Action.LoadAPicture Hotspot(4), "4.jpg"
   if d = 5 then Action.LoadAPicture Hotspot(4), "5.jpg"
   if d = 6 then Action.LoadAPicture Hotspot(4), "6.jpg"
   if d = 7 then Action.LoadAPicture Hotspot(4), "7.jpg"
   if d = 8 then Action.LoadAPicture Hotspot(4), "8.jpg"
   if d = 9 then Action.LoadAPicture Hotspot(4), "9.jpg"
   if d = 10 then Action.LoadAPicture Hotspot(4), "10.jpg"

End Sub



This goes into Frame Properties:
Code: Select all
SpotA

SpotB

SpotC

SpotD


Make sure you do not change the order in the Frame Properties or it will not work. And you can use this procedure in all the frames you need to.
lisbonsasori
New Member
 
Posts: 5
Joined: Sun May 02, 2010 7:35 pm

Postby Lyberodoggy » Thu May 06, 2010 9:32 pm

you can actually change the big one into this:

Code: Select all
Sub SpotA
   randomize
   i = int( RND * 10 ) + 1
   a = i

   Action.LoadAPicture Hotspot(1), cstr(a)+".jpg"

End Sub

Sub SpotB
   Do Until i <> a
      randomize
      i = int( RND * 10 ) + 1
   Loop

   b = i
   Action.LoadAPicture Hotspot(2), cstr(b)+".jpg"

End Sub

Sub SpotC
   Do Until i <> a and i <> b
      randomize
      i = int( RND * 10 ) + 1
   Loop

   c = i
   Action.LoadAPicture Hotspot(3), cstr(c)+".jpg"

End Sub

Sub SpotD
   Do Until i <> a and i <> b and i <> c
      randomize
      i = int( RND * 10 ) + 1
   Loop

   d = i
   Action.LoadAPicture Hotspot(4),  cstr(d)+".jpg"

End Sub



and it could be even changed to have one procedure do the thing for all of the hotspots
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby lisbonsasori » Thu May 06, 2010 10:03 pm

I think there is a consideration to be made regarding your approach.

It will work fine if your images are named precisely as the ones in my previous example.

But images can be named anything and if they have any different name the Action.LoadAPicture Hotspot(), cstr()+".jpg? function will not work.

So, one must always be sure to rename the images accordingly.
lisbonsasori
New Member
 
Posts: 5
Joined: Sun May 02, 2010 7:35 pm

Postby Mystery » Thu May 06, 2010 10:44 pm

That's true :)

Good planning can make a difference :lol:
I'm not laughing at you, but myself, because I've run into such situations where I have made my work unnecessarily difficult by not planning well in advance :P

Thank you both for your contributions, I'm sure they will be helpful to other game creators :)
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby Lyberodoggy » Fri May 07, 2010 1:00 pm

lisbonsasori wrote:I think there is a consideration to be made regarding your approach.

It will work fine if your images are named precisely as the ones in my previous example.

But images can be named anything and if they have any different name the Action.LoadAPicture Hotspot(), cstr()+".jpg? function will not work.

So, one must always be sure to rename the images accordingly.


Yeah, I did that coding considering that you have named all of the pictures using a pattern. And that's the best thing to do to keep track too.
For example, if you use the animation maker plugin you actually need to have your images filenames using a prefix and numbers to get it to work.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron