Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / undo/redo commands

Author
Message
nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 3rd Apr 2011 03:45
do anyone know how to make undo and redo commands? i am building an level editor that can more or less work without it but i still want ot make these two options available
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 3rd Apr 2011 07:19
To undo, the app first needs record every destructive action the user makes. So when they add something, delete, move, resize, rename etc etc it records this action.

The action data needs to remember the state of the changed 'thing' prior to the changes being made. So if the users changes the colour an object say, then it'll need to drop a 'colour change' action onto the stack with the objects original colour.


When the users undoes the last thing they did, the Undo routine looks at the last item on the action stack. Then reverses the process. So if this action was a 'change colour', then the routine grabs the old colour from within the action data and writes this back to the object. Restoring it's state for the user.


Anyway, hope that gives you a starting place.

nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 3rd Apr 2011 19:33
i have tried to use arrays but i am having difficulties with this due to fact that my editor various types of data, and this is very confusing stuff, can someone show me how to make undo function for object changing color
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 3rd Apr 2011 19:54
It's tricky to do. Here are my notes on what I do for my level editor Undo/Redo. It is working out pretty well.

I have two variable size 1D arrays which act like stacks/queues when convenient: ChangeLog() and RedoLog()
They both start out empty and are dim'd with using the same type which has enough info to hold Old/New states for tiles.

Whenever the user does an action on a tile in the editor I log it in ChangeLog()

If the user hits CTRL-Z I do the following:
- Undo the change on the map by replacing the New tile with the Old tile from ChangeLog()
- Take it out of ChangeLog()
- Put it onto RedoLog()

If the user hits CTRL-Y I do the following:
- Redo the change on the map by replacing the Old tile with the New tile from RedoLog()
- Take it out of RedoLog()
- Put it onto ChangeLog()

When the user does an action in the editor I clear RedoLog()
The idea is you cannot redo steps once you've "broken the chain" of events.


A 3D marble platformer using Newton physics.

Login to post a reply

Server time is: 2026-07-11 14:55:11
Your offset time is: 2026-07-11 14:55:11