Want to see something really ugly?

For discussions about game development that does not fit in any of the other topics.
Post Reply
Cayle
Posts: 272
Joined: Fri Jul 03, 2009 4:45 am

Want to see something really ugly?

Post by Cayle »

Using VBA to generate python code from Excel sheets makes for some disgusting spaghetti...

Code: Select all

    spellBookTemplateLibraryHeaderList(1,1) = "def createSpellBookInInventory(templateID, ownerKey):" & vbCrLf & "    returnKey = None" & vbCrLf
	spellBookTemplateLibraryHeaderList(1,2) = "    try:"
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "        owner = ownerKey.get()"
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "        owner.inventory.contents.append(newEntity.key)"
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "        newEntity.onAcquireItem()" 'The item fires its onAquire event
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "        owner.onAcquireItem()"     'The new owner fires its onAquire event
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "    except AttributeError:"    
	spellBookTemplateLibraryHeaderList(1,2) = spellBookTemplateLibraryHeaderList(1,2) & vbCrLf & "        raise Exceptions.NoSuchEntityError('There is no datastore entity associated with key' %ownerKey)" & vbCrLf 
    spellBookTemplateLibraryHeaderList(2,1) = "def createSpellBookAtLocation(templateID, locLatitude, locLongitude):" & vbCrLf & "    returnKey = None" & vbCrLf
    spellBookTemplateLibraryHeaderList(2,1) = spellBookTemplateLibraryHeaderList(2,1) & "    if locLongitude is None:" & vbCrLf
    spellBookTemplateLibraryHeaderList(2,1) = spellBookTemplateLibraryHeaderList(2,1) & "        raise Exceptions.LocationlessEntity('SpellBook %s requires a longitude when being created' %templateID)" & vbCrLf
    spellBookTemplateLibraryHeaderList(2,1) = spellBookTemplateLibraryHeaderList(2,1) & "    if locLatitude is None:" & vbCrLf
    spellBookTemplateLibraryHeaderList(2,1) = spellBookTemplateLibraryHeaderList(2,1) & "        raise Exceptions.LocationlessEntity('SpellBook %s requires a latitude when being created' %templateID)" & vbCrLf
	spellBookTemplateLibraryHeaderList(2,3) = ", locLatitude=locLatitude, locLongitude=locLongitude"
And yeah, I've got some long variable names. I like them to be self descriptive, so that I understand what they mean when I go back and look at them a year or two later.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Want to see something really ugly?

Post by Jackolantern »

Wow, VBA generating Python? haha :lol:
The indelible lord of tl;dr
Cayle
Posts: 272
Joined: Fri Jul 03, 2009 4:45 am

Re: Want to see something really ugly?

Post by Cayle »

Yeah, I'll post a demo video of the content editor for Magicus Occultus in a couple of weeks. It uses something like 60 excel sheets and 3-4k lines of VBA to generate some of the python modules. :P I'm finishing up removing some nastiness and making sure everything works. When I've got valid exports again (they've been broken since I switched from DB to NDB), I'll wrap everything up into a nice little VSTO app.

Using VBA is like going on an archaeological dig. It really feels like an archaic language; especially when compared to a duck typed, multiple inheritance language like python. It even makes a distinction between subroutines and functions!!!
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Want to see something really ugly?

Post by hallsofvallhalla »

wow now this is interesting. Python and VB sleeping together. Wonder what kind of baby this produces?
Post Reply

Return to “General Development”