Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 10th, 2025, 11:56 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Passing variables in functions
PostPosted: December 22nd, 2005, 5:57 pm 
Offline

Joined: November 3rd, 2004, 6:44 pm
Posts: 59
Location: Ipswich, UK
I am producing a simple game that I want to flash 3 images when the game is won. From my understanding of fork and functions I thought I could pass the names of the images to the functions below so that the flash function is reusable.

Unfortunately I can't get it to work.
Anyone got any ideas?



// ======================== TO FLASH CORRECT OBJECTS

function MySetFlare(image1,image2,image3)
{

//Debug.trace(image1) This shows that the name of the image does get passed.

image1.SetFlare(6,6,0,RGB(255,0,0),5)
image2.SetFlare(6,6,0,RGB(255,0,0),5)
image3.SetFlare(6,6,0,RGB(255,0,0),5)
}

function MyRemoveFlare(image1,image2,image3)
{
image1.RemoveFlare()
image2.RemoveFlare()
image3.RemoveFlare()
}

function FlashWinner()
{
var Loop =1
while (Loop <100)
{
fork (MySetFlare)

wait (.2)
fork (MyRemoveFlare)
wait (.2)
Loop++
}
}


Regards

Clive Cartmel
Happy Christmas everyone!


Top
 Profile  
 
 Post subject:
PostPosted: December 22nd, 2005, 8:44 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Hi Clive,
from my understanding of your script -- you are calling functions that contain parameters with function calls that don't -- I've removed the function parameters to get it working.
fork is not necessary in this script -- won't make any difference if you use it or not.
see attached pub

//############################################
// == TO FLASH CORRECT OBJECTS

function MySetFlare()
{
image1.SetFlare(6,6,0,RGB(255,0,0),5)
image2.SetFlare(6,6,0,RGB(255,0,0),5)
image3.SetFlare(6,6,0,RGB(255,0,0),5)
}

function MyRemoveFlare()
{
image1.RemoveFlare()
image2.RemoveFlare()
image3.RemoveFlare()
}

function FlashWinner()
{
var Loop =1
while (Loop <100)
{
//fork(MySetFlare)
MySetFlare()
wait (.2)
//fork (MyRemoveFlare)
MyRemoveFlare()
wait (.2)
Loop++
}
}

// make the call
FlashWinner()
//#########################################

cheers
Paul


Top
 Profile  
 
 Post subject: Passing variables in functions
PostPosted: December 22nd, 2005, 11:06 pm 
Offline

Joined: November 3rd, 2004, 6:44 pm
Posts: 59
Location: Ipswich, UK
Thanks for your reply Paul.

Sorry, my description was perhaps a little poor.

The game is a variation on Noughts and Crosses. Depending on who has won and which row/column they have won determines which objects flash. I have named the objects XTL, XTM and XTR for player X top left etc and have developed a functional script that determines if they win a square (after answering a question) and then if they win the game. The script that determines that they have won also works out which squares they have clicked on in order to win. It is these that I need to pass to the functions in order for the winning flash. The determining script calls the FlashWinner but only works if I hard code the image name into the script as you have done.

Does this explain it any better?

Thanks for your interest.

Clive


Top
 Profile  
 
 Post subject:
PostPosted: December 23rd, 2005, 2:31 am 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Hi Clive,
More info always helps -- In that case you will need to use "this.GetName()" on a suitable trigger inside each item and feed it as a parameter to the function.
The function can then use eval to stitch something useable together -- the attached imp should give you something to go on.

Got to get back to work -- the alligators are circling again :-)

Paul


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 49 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group