RPG Tutorial with sprite kit and swift 3 part 21 >> SKAction.run did not work

Home 3 Forums Tutorial Help Any Other Tutorials RPG Tutorial with sprite kit and swift 3 part 21 >> SKAction.run did not work

This topic contains 5 replies, has 2 voices, and was last updated by  Bastian 2 weeks, 3 days ago.

  • September 24, 2017 at 6:14 am #171818

    Hi all,

    first of all, I will thank you so much for this tutorial.
    It makes so much fun to work with and I hope I will learn enough to make my own game in the future. 😀

    But I got a problem and it appeared after part 21 of your tutorial (by minute 20:11).
    Link: https://cartoonsmart.com/?portfolio=role-playing-games-tutorial-with-sprite-kit-and-swift-3-part-21-item-requirements-and-info-text

    My “random” speeches aren’t random anymore and my “WorldItems” (“NPC’s” too) only speaks the same line over and over again.

    I hope someone can help me.

    I don’t want to write too much, but I tried a little debugging and I hope it helps.
    I wrote in every if-statement a print() with an different number and it shows that my SKAction.run sequence to set (currentSpeech = “”) never runs.

    In my log (console output), I show how I walk into the same NPC three times times. I waited a few seconds between every contact. But I also tried to remove the “wait” sequence from the SKAction in another try and it was the same result.

    My speak() function: https://ibb.co/dttNzQ
    IMG_2962

    My output: https://ibb.co/ejpvKQ
    IMG_2963

    Please help. 🙂

    With kind regards

    PS: My thread was deleted directly after I created it and I wrote an email to you directly, but I think its better in the community. This way others may also have the advantages. 🙂

    Oh… my function:

        func speak() -> String {
            
            if ( currentSpeech == "" ) {
                
                if (alreadyContacted == false ) {
                   
                    let randomLine:UInt32 = arc4random_uniform( UInt32( initialSpeechArray.count ) )
                    currentSpeech = initialSpeechArray[ Int (randomLine) ]
                    
                    print(">>>>>>>>>Posi 1<<<<<<<<<")
                    print(currentSpeech)
                    
                }
                else {
                    
                    let randomLine:UInt32 = arc4random_uniform( UInt32( reminderSpeechArray.count ) )
                    currentSpeech = reminderSpeechArray[ Int (randomLine) ]
                    
                    print(">>>>>>>>>Posi 2<<<<<<<<<")
                    print(currentSpeech)
                    
                }
                let wait:SKAction = SKAction.wait(forDuration: 3)
                let run:SKAction = SKAction.run {
                    
                    self.currentSpeech = ""
                    
                    print(">>>>>>>>>Posi 5<<<<<<<<<")
                    print(self.currentSpeech)
                }
                //Führt die Sequenz aus
                self.run(SKAction.sequence([wait, run]))
                
                print(">>>>>>>>>Posi 3<<<<<<<<<")
                print(currentSpeech)
            }
            
            print(">>>>>>>>>Posi 4<<<<<<<<<")
            print(currentSpeech)
            
            return currentSpeech
        } // speak()
  • October 2, 2017 at 6:04 pm #172625

    Did you check to see if this is an issue in the kit itself? Might be something that got patched up when testing the kit.

  • October 5, 2017 at 12:58 pm #174522

    Thanks for your help. 🙂
    Hm… I wrote it all with the help of your tutorials (I’m still on part 24).
    But I switched to swift 4 in the middle of the project.

    I have the same with my WorldItems, like the Castle.
    If the castle is not yet open and I try to enter it several times, only one text will be displayed (getInfo() function).

    //Sorgt dafür das ein ZufallsSatz zurück gegeben wird
    func getInfo() -> String {
            
        //Prüft ob currentInfo leer ist
        if (currentInfo == "") {
                
            //Prüft ob das WorldItem bereits geöffnet wurde, oder nicht
            if (isOpen == false) {
                    
                //Prüft ob sich im lockedTextArray mindestens eine Zeile befindet
                if (lockedTextArray.count > 0) {
                        
                    //Erzeugt anhand der Array anzahl eine Zufallszahl und schreibt den Text an der Stelle in currentInfo
                    let randomLine:UInt32 = arc4random_uniform( UInt32( lockedTextArray.count ))
                    currentInfo = lockedTextArray[ Int (randomLine) ]
                        
                }
            } else {
                if (openTextArray.count > 0) {
                        
                    let randomLine:UInt32 = arc4random_uniform( UInt32( openTextArray.count ))
                    currentInfo = openTextArray[ Int (randomLine) ]
                        
                }
            } // if
                
            //Erstellt eine Sequenz, damit der Text nach 3 Sekunden verschwindet
            let wait:SKAction = SKAction.wait(forDuration: 3)
            let run:SKAction = SKAction.run {
                self.currentInfo = ""
            }
                
            //Führt die Sequenz aus
            self.run(SKAction.sequence([wait, run]))
                
        }
            
        //Funktion gibt currentInfo zurück
        return currentInfo
            
    } // getInfo()
    • October 5, 2017 at 3:07 pm #174523

      Switching from Swift 3 to 4 won’t affect anything. Identical as far as I can tell. Have you tried running a print statement on openTextArray or lockedTextArray just to make sure they actually do have more than one item in the array?

  • October 6, 2017 at 6:18 am #174538

    Hm… I tried that.
    It printed all my lines (two lines to be exact), but I found out, that the function “getInfo()” is working correctly. My lines are changing after 3 seconds.

    Still don’t know why my “speak()” function still not working. 🙁
    I tried to compare the source code of these two functions, but I can’t find any difference what could cause it.

    I’m still thinking that “self.run( SKAction.sequence([wait, run]))” isn’t running?!

  • October 6, 2017 at 7:08 am #174539

    Ok, now I’m really confused.
    I downloaded your hole RPG Kit.
    Tried it on my iPhone and the NPCs have different lines.

    So I tried to copy your “speak()” into my project.
    I commented out my old function.

    And its the same… my NPC lines dont change and I have more than one line in my property list.

    https://ibb.co/d62PrG
    IMG_3075

You must be logged in to reply to this topic.