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

2024/12/3

trying to get an int from an actor in a different world to show it in the end

Alizee Alizee

2024/12/3

#
i am trying to get the int vie from Calamitas and show it in my death screan(EcranDeMort) but i cant get it with getObjects(Calamitas.class).get(vie); because it isn't in the world EcranDeMort. my code from my EcranDeMort: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class ecrandemort here. * * @author (your name) * @version (a version number or a date) */ public class EcranDeMort extends World { MessageDeMort MessageMort; int vie = getObjects(Calamitas.class).get(vie); /** * Constructor for objects of class ecrandemort. * */ public EcranDeMort() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 800, 1); MessageMort = new MessageDeMort(); addObject(MessageMort,400,200); showText("Il restais ", 400, 400); } } the relevent code from Calamitas: Actor Bl = (Actor)getWorld().getObjects(Blahaj.class).get(0); if (Bl.getImage().getTransparency() == 0){ setRotation(0); peuAttaque = false; rep = 40; musiquePhase1.stop(); musiquePhase2.stop(); if(peuJouerSon == true){ tuAPerdu.play(); peuJouerSon = false; } if(timer > animation + 100 && tuAPerdu.isPlaying() && rep > 0){ animation = timer; setLocation(getX(),getY()+1); rep--; }else if(timer > animation + 100 && ! tuAPerdu.isPlaying() && sonDisparition == true){ im.setTransparency(0); disparition.play(); for(int j = 0; j<20; j++){ getWorld().addObject(new particule(), getX(), getY()); } sonDisparition = false; animation = timer; }else if(timer > animation + 1000 && sonDisparition == false){ EcranDeMort EcranDeMort = new EcranDeMort(); Greenfoot.setWorld(EcranDeMort); } } tanks in advance
danpost danpost

2024/12/4

#
Alizee wrote...
i am trying to get the int vie from Calamitas and show it in my death screan(EcranDeMort) but i cant get it with getObjects(Calamitas.class).get(vie); because it isn't in the world EcranDeMort. << Code Omitted >>
The easiest way to get it across worlds is to pass it when the one world creates the other. This is done by adding an int argument to the constructor of the world being created:
import greenfoot.*;

public class EcranDeMort extends World
{
    MessageDeMort MessageMort;
    int vie;
    
    public EcranDeMort(int vieEnd)
    {    
        super(800, 800, 1); 
        vie = vieEnd;
        MessageMort = new MessageDeMort();
        addObject(MessageMort,400,200);
        showText("Il restais ", 400, 400);
    }
}
(note lines 6, 8 and 11) Just put the value within the parentheses when creating the new world:
 ...   new EcranDeMort( /**  value here */ )  ...
(while you are still in the world where the datum is located)
Alizee Alizee

2024/12/4

#
tank you
You need to login to post a reply.