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

2021/2/26

How making a 2 ways dialogue ?

1
2
mariq_rasyid29 mariq_rasyid29

2021/2/26

#
i used showtext code in my world but look like common if i press A will be show the next text but always fail
danpost danpost

2021/2/26

#
mariq_rasyid29 wrote...
i used showtext code in my world but look like common if i press A will be show the next text but always fail
Show failed codes (all related codes in world class).
mariq_rasyid29 mariq_rasyid29

2021/2/26

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class PlaygameHome here.
 *
 * @author (Muhamad Ariq Rasyid)
 * @version (1.0 19 Feb 2021)
 */
public class PlaygameHome extends World
{
    /**
     * Constructor for objects of class PlaygameHome.
     *
     */
     
    public PlaygameHome()
    {   
        // Create a new world with 800x600 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        /**
         * NPC
         */
        //WolfLink
        WolfLink wolfLink = new WolfLink();
        addObject(wolfLink,419,68);
        //Cerberus
        Cerberus cerberus = new Cerberus();
        addObject(cerberus,704,525);
        Werewolf werewolf = new Werewolf();
        addObject(werewolf,33,533);
        Ryuza ryuza = new Ryuza();
        addObject(ryuza,451,535);
         
        /**
         * Dens
         */
        //Player home
        Den den = new Den();
        addObject(den,65,67);
        //Pack Den
        Den2 den2 = new Den2();
        addObject(den2,764,38);
         
        /**
         * Player
         */
        //Player
        Player player = new Player();
        addObject(player,291,163);
                 
        /**
         * MapsAttribute
         */
         //River
        River river = new River();
        addObject(river,238,564);
        //Stone
        Stone stone = new Stone();
        addObject(stone,386,577);
        Stone2 stone2 = new Stone2();
        addObject(stone2,384,534);
        Stone3 stone3 = new Stone3();
        addObject(stone3,351,509);
        Stone4 stone4 = new Stone4();
        addObject(stone4,304,508);
        Stone5 stone5 = new Stone5();
        addObject(stone5,254,510);
        Stone6 stone6 = new Stone6();
        addObject(stone6,205,513);
        Stone7 stone7 = new Stone7();
        addObject(stone7,155,517);
        Stone9 stone9 = new Stone9();
        addObject(stone9,106,513);
        Stone10 stone10 = new Stone10();
        addObject(stone10,86,550);
        Stone11 stone11 = new Stone11();
        addObject(stone11,86,580);
        //Trees
        Pine1 pine1 = new Pine1();
        addObject(pine1,109,19);
        Pine2 pine2 = new Pine2();
        addObject(pine2,13,48);
        //Flatfrom
        Flatfrom1 flatfrom1 = new Flatfrom1();
        addObject(flatfrom1,24,582);
        Flatfrom2 flatfrom2 = new Flatfrom2();
        addObject(flatfrom2,452,582);
        Flatfrom3 flatfrom3 = new Flatfrom3();
        addObject(flatfrom3,701,578);
        Flatfrom4 flatfrom4 = new Flatfrom4();
        addObject(flatfrom4,416,21);
        //WolfSatue
        WolfStatue wolfStatue = new WolfStatue();
        addObject(wolfStatue,426,254);
        //dialog
        addObject(new Label("",60),24,513);
           }
 
       
       
    
}
that is the code of my world but idk in where i must to input it
mariq_rasyid29 mariq_rasyid29

2021/2/26

#
but idk im used label is failed also used showtext too
danpost danpost

2021/2/26

#
mariq_rasyid29 wrote...
but idk im used label is failed also used showtext too
Where is the text to be shown. When using label, showing "" is invisible and using showText removes any text. The dialog should probably be in a String array. An int index pointer can be used to track progress through the array. Maybe a Dialog class might be helpful, to accept the array and control the displayed text.
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
mmm i have dialog class but idk how to call it to others class here the code of dialog class
1
2
3
4
5
6
7
8
9
10
11
12
13
public Dialogue(String text)
    {
        GreenfootImage img = new GreenfootImage (text.length()*20,50);
        img.drawString(text, 30, 20);
        setImage(img);
    }
      
    public void setText(String text)
    {
        GreenfootImage img = getImage();
        img.clear();
        img.drawString (text, 30, 20);
    }
danpost danpost

2021/2/28

#
I was thinking more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private String[] dialogue;
private int index;
 
public Dialogue(String[] dialogue)
{
    this.dialogue = dialogue;
    index = 0;
    setText();
}
 
private void setText()
{
    setImage(new GreenfootImage(dialogue[index], 28, Color.BLACK, Color.WHITE));
}
 
public void nextText()
{
    if (++index < dialogue.length) setText();
    else getWorld().removeObject(this);
}
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
mmm sir how about if i press A will be show the next text if i used your code, sir?
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
mm sir i get error it said "
1
incompatibles types : java.lang.String cannot be converted to javalang.String[]
" after im input any text
danpost danpost

2021/3/1

#
mariq_rasyid29 wrote...
i get error it said "
1
incompatibles types : java.lang.String cannot be converted to javalang.String[]
" after im input any text
Input an array of text:
1
2
3
4
5
6
7
// example
String[] dialog =
{
    "Press A for next text",
    "Press H to howl"
};
Dialogue dialogue = new Dialogue(dialog);
Then in act:
1
2
3
4
if (!getObjects(Dialogue.class).isEmpty() && "a".equals(Greenfoot.getKey())
{
    ((Dialogue)getObjects(Dialogue.class).get(0)).nextText();
}
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
ohhh i see thx sir i got it
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
ohhh i seee thx sir
mariq_rasyid29 mariq_rasyid29

2021/3/1

#
mmmmm now how if Player move to others world the dialogue is removed for example here the code from someone NPC class
1
2
3
4
5
6
7
8
9
10
public void DigimonandPokemon() {
       String input = Greenfoot.ask("Rayquaza : 'Are You Sure Want To Digimon And Pokemon World, Alpha?'");
       if ("yes".equals(input)) {
           if (getWorld() instanceof PlaygameHome)
           ((PlaygameHome)getWorld()).Back.stop();
           Greenfoot.setWorld (new DigimonandPokemon());}
           else
            if("no".equals(input)){
             Greenfoot.setWorld(new PlaygameHome());  }
           }
if the player input no, so still in the PlaygameHome World but the dialog still there in PlaygameHome World how to remove it?
danpost danpost

2021/3/1

#
Replace line 9 with:
1
2
3
World pgh = new PlaygameHome();
pgh.removeObjects(pgh.getObjects(Dialogue.class));
Greenfoot.setWorld(pgh);
mariq_rasyid29 mariq_rasyid29

2021/3/2

#
mmmm now how if player touch WolfStatue class will be show the text? here the code of Wolf Statue class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class WolfStatue extends Freature
{ String[] dialog3 =
     {
    "The Greatest of Alpha\n Blizzard Wolf Smith."
      };
    
    /**
     * Act - do whatever the WolfStatue wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {touch();
    }
    public void touch()
    {if(isTouching(Player.class))
        {
    }
     
   }
}
There are more replies on the next page.
1
2