This site requires JavaScript, please enable it in your browser!
Greenfoot back
Lamby777
Lamby777 wrote ...

2017/10/16

How do I make a function with an arguement?

Lamby777 Lamby777

2017/10/16

#
Before I say anything, here's my code for you to reference back to:
import greenfoot.*;
import java.awt.Color;
/**
 * Write a description of class Explains here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Explains extends Actor
{
    
    long lastTime = System.currentTimeMillis();
    
    /**
     * Act - do whatever the Explains wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        text();
        start();
    }
    
    public void wait(w);
    {
        long cTime  = System.currentTimeMillis();
        if (cTime >= lastTime + w) //5000ms = 5s
            {
                lastTime  = cTime;
            }
    } 
    public void text()
    {
        setImage(new GreenfootImage("DETECTIVE", 24, Color.RED, Color.WHITE));
        wait(2500);
    }
    
    public void start()
    {
        
    }
}
So, I was making a game, and wanted to display text but with delays in between. I didn't want to use wait(5); or anything similar. I wanted to count system time in ms, and use a function to wait in just that actor, but it's not letting me do
public void wait(w);
I'm used to python, making new functions with the arguements in parentheses... I only made 1 project in Greenfoot, so I don't know much about this kind of stuff.
danpost danpost

2017/10/16

#
Use the 'delay(int)' method of the Greenfoot class.
You need to login to post a reply.