Kann sich das bitte jemand anschauen???

  • Hallo, ich brauche dringend Hilfe...


    Ich wollte mit der Horn Speci aus dem Beispielmod 2 verschiedene Melodien abspielen. Irgendwie hat das aber nicht funktioniert. Hab einiges versucht und das Spiel zig mal gestartet, leider ohne Ergebniss...
    So wie es jetzt ist wird per Knopfdruck nur die PThorn1.wav abgespielt...
    Kann mir jemand sagen was ich falsch gemacht hab?


    ?(?(?(


    Danke schonmal im Vorraus



    [lua]--
    -- lizard2000
    -- Specialization for lizard2000 mod
    --
    -- @author Stefan Geiger
    -- @date 10/01/09
    --
    -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.


    PThorn = {};


    function PThorn.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
    end;


    function PThorn:load(xmlFile)
    horn1SoundFile = Utils.getFilename("PThorn1.wav", self.baseDirectory);
    horn2SoundFile = Utils.getFilename("PThorn2.wav", self.baseDirectory);
    self.horn1SoundId = createSample("PThorn1sound");
    self.horn2SoundId = createSample("PThorn2sound");
    loadSample(self.horn1SoundId, horn1SoundFile, false);
    loadSample(self.horn2SoundId, horn2SoundFile, false);
    self.horn1Playing = false;
    self.horn2Playing = false;
    end;


    function PThorn:delete()
    delete(self.burnerSoundId);
    end;


    function PThorn:mouseEvent(posX, posY, isDown, isUp, button)
    end;


    function PThorn:keyEvent(unicode, sym, modifier, isDown)
    end;


    function PThorn:update(dt)
    if self:getIsActiveForInput() and self:getIsActiveForSound() and InputBinding.isPressed(InputBinding.PThorn1) then
    if not self.horn1Playing then
    playSample(self.horn1SoundId, 0, 0.35, 0);
    self.horn1Playing = true;
    end;
    else
    if self.horn1Playing then
    stopSample(self.horn1SoundId);
    self.horn1Playing = false;
    end;
    end;

    if self:getIsActiveForInput() and self:getIsActiveForSound() and InputBinding.isPressed(InputBinding.PThorn2) then
    if not self.horn2Playing then
    playSample(self.horn2SoundId, 0, 0.35, 0);
    self.horn2Playing = true;
    end;
    else
    if self.horn2Playing then
    stopSample(self.horn2SoundId);
    self.horn2Playing = false;
    end;
    end;
    end;


    function PThorn:draw()
    end;


    [/lua]

  • So, habe den updateteil mal ein wenig aufgeräumt.


    So Sachen wie self:getIsActiveForInput()] brauchst du nur einmal abfragen. Ist also bei den Tastenevents überflüssig.
    [lua]
    function PThorn:update(dt)
    if self:getIsActiveForInput()
    if self:getIsActiveForSound()
    if InputBinding.isPressed(InputBinding.PThorn1) then
    if not self.horn1Playing then
    playSample(self.horn1SoundId, 0, 0.35, 0);
    self.horn1Playing = true;
    end;
    else
    if self.horn1Playing then
    stopSample(self.horn1SoundId);
    self.horn1Playing = false;
    end;
    end;

    if InputBinding.isPressed(InputBinding.PThorn2) then
    if not self.horn2Playing then
    playSample(self.horn2SoundId, 0, 0.35, 0);
    self.horn2Playing = true;
    end;
    else
    if self.horn2Playing then
    stopSample(self.horn2SoundId);
    self.horn2Playing = false;
    end;
    end;
    end;
    end;
    end;
    [/lua]


    mfg

  • Hallo FIAT80-90DT,


    vielen Dank für Deine schnelle Antwort. Gab noch zwei kleine Fehlermeldungen in der Log, aber anhand selbiger konnte ich das jetzt fertig machen:


    [lua]function PThorn:update(dt)
    if self:getIsActiveForInput() and self:getIsActiveForSound() then
    if InputBinding.isPressed(InputBinding.PThorn1) then
    if not self.horn1Playing then
    playSample(self.horn1SoundId, 0, 0.35, 0);
    self.horn1Playing = true;
    end;
    else
    if self.horn1Playing then
    stopSample(self.horn1SoundId);
    self.horn1Playing = false;
    end;
    end;

    if InputBinding.isPressed(InputBinding.PThorn2) then
    if not self.horn2Playing then
    playSample(self.horn2SoundId, 0, 0.14, 0);
    self.horn2Playing = true;
    end;
    else
    if self.horn2Playing then
    stopSample(self.horn2SoundId);
    self.horn2Playing = false;
    end;
    end;
    end;
    end;[/lua]


    Vielen Dank nochmal für Deine Hilfe, jetzt funktionierts genauso wie ich gern hätte...
    :thumbsup::thumbsup::thumbsup:

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!