Scripting Error

I'm trying to write a very simple script to undo the last action but keep getting a Can't find variable undo error in my undo() call

 

any ideas

Comments

  • SofaCitizenSofaCitizen Posts: 1,896

    Sounds like you need to define the undo variable in your code?

    You'd probably get more help if you post your script (host it elsewhere since attachments are broken) and perhaps move your post to the scripting forum: https://www.daz3d.com/forums/categories/daz-script-developer-discussion

  • BrahannBrahann Posts: 18

    thanks

     

  • BrahannBrahann Posts: 18

    I'm trying to write a very simple script to undo the last action but keep getting a Can't find variable undo error in my undo() call

     

    any ideas

  • Cris PalominoCris Palomino Posts: 11,397

    Threads merged. Please do not post the same thread in more than forum. It becomes confusing trying to remember what responses got posted where.

  • frank0314frank0314 Posts: 14,066
    edited July 2023

    If you want to change forums go to your opening post and where the forum name is and select the drop-down and point it to the forum you wish to post it to.

    Post edited by frank0314 on
  • Richard HaseltineRichard Haseltine Posts: 101,032

    What is the script? It's really hard to troubleshoot from what little information you have given.

  • BrahannBrahann Posts: 18

    I'm trying to write a very simple script to undo the last action but keep getting a Can't find variable undo error in my undo() call

     

    any ideas

  • SofaCitizenSofaCitizen Posts: 1,896

    Isn't this the third thread you have started on this - still with no extra info?

  • BrahannBrahann Posts: 18

    what extra info basically I just want a script to undo an action such as applying a L.I.E.

    any thing I try results in a cant find undo()

     

    e.g.

    (function(){

    beginUndo();

    undo();

    acceptUndo("Undo");

    })();

    gives

    Executing Script...
    Script Error: Line 5
    ReferenceError: Can't find variable: undo
    Stack Trace: ()@:5
    Error executing script on line: 5
    Script executed in 0 secs 2 msecs.

     

  • SofaCitizenSofaCitizen Posts: 1,896
    edited July 2023

    Yes, like I said in your other thread, you have not defined the undo function. e.g.

    (function(){
    	var undo = function() {
    		// Do a thing that you want to be able to undo
    	}
    
    	beginUndo();
    
    	undo();
    
    	acceptUndo("Undo");
    
    })();
    Post edited by SofaCitizen on
  • Richard HaseltineRichard Haseltine Posts: 101,032
    edited July 2023

    Threads merged again. If youw ant to move this to the sceripting forunm edit the first post and select the desired forum from the drop-down list.

    The built-in undo actuions here are for adding actions to the undo stack, so that they will appear under edit>Undo. If you want to abort an operation then it is up to you to reverse the steps, using your own code, and then cancel the undo creation - if you don't want to cancel then you accept the undo. You snippet would add an entry to the undos tack, even though you had presumably nulled the actions the script had performed.

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/global

    Post edited by Richard Haseltine on
  • BrahannBrahann Posts: 18

    I could be being an absolute idiot here but  undo seems to be declared as a method in the dazundo stack the question is how to call it without gettig an error?

     

    Dave

     

     

  • Richard HaseltineRichard Haseltine Posts: 101,032

    BeginUndo tells Daz Studio to add the current state of the scen to the stack

    Then you (try to) do stuff that modifies the scene

    Then you AcceptUndo to tell Daz Studio that the process is complete, or if the operation was cancelled or failed you use cancelUndo to tell DS to drop the entry.

    Once you have done, and used AcceptUndo, you could I suppose trigger an Undo action - that would clear out any changes your script had made but ti would also leave them available as a redo until soemthing else was added to the stack. Undo within the script is the author's responsibility, as far as I know.

  • SofaCitizenSofaCitizen Posts: 1,896

    If you literally just want to call the undo function from the stack then you should delete your entire script and replace it with the following:

     

    UndoStack.undo();

     

    That one-line script will do what the Undo button / Ctrl-Z does - is that what you wanted to do?

  • Richard HaseltineRichard Haseltine Posts: 101,032

    But don't do that in the middle of a Begin/Accept or Cancel block - I think it would, at best, fail.

Sign In or Register to comment.